• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EntityManager and Transactions

 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding of Entity Managers ( EM ) and Transaction is ::

"Application Managed " EM can be injectected by first injecting EntityManagerFactory .

My question is ::

Such a EM is "ApplicationManaged"
Since the EM is in a "Managed environment " the existing Tx will be "JTA"

Can the EM start a new Transaction ?
Or is the EM ONLY allowed to JOIN an existing Tx ?

The TX will be a JTA one ?

Confused

Thanks ,
~satish
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the implementation, but basically how Hibernate works is that you can write the code to get the Transaction and begin and then commit when done, say within a DAO, if you are not in a Java EE container then Hibernate will create its own Transaction and use it, if it is in a Container that provides JTA then it will just join the transaction that it creates.

So it does not require a Java EE Container and JTA to have transactions in Hibernate. I am pretty sure TopLink works in the same way.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic