Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java persistence api transaction problem  RSS feed

 
mojo lai
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use JPA in servlet

I must explicit call commit() / rollback() /begin();

While I use JPA in Session Bean

I don't ask to do that

IS that because ejb container support transaction but web container doesn't ??

thank you.
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it is certainly true that web containers do not have container-demarcated transactions, but the point that you are referring to might just be the difference between using a JTA and resosurce-local persistence unit.

In other words, if you used a JTA EntityManager in your serlvet then you still would not call begin/commit on the EntityManager transaction (EntityTransaction); you would be expected to demarcate JTA transactions using the UserTransaction API, e.g. UserTransaction.begin(), etc.
 
mojo lai
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you , one more question

The reason why I don't call EntityTransaction.begin(),EntityTransaction.commit()
in EJB is that EJB container use "container-demarcated transactions" for me ?
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The reason why I don't call EntityTransaction.begin(),EntityTransaction.commit()
in EJB is that EJB container use "container-demarcated transactions" for me ?

Right, but also because the persistence unit is defined (or defaulted when used in a container) to be of the JTA transactional type.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!