Problem with understanding Transaction Management Demarcation
Mario Wojcik
Greenhorn
Joined: Jan 21, 2010
Posts: 1
posted
0
Hi
I'm preparing to SCBCD exam and I have problems with understanding various types of Entity Managers.
I know that Application Managed EM can be JTA or ResourceLocal, but what about Transaction Management Demarcation(bean-managed transaction demarcation,or container-managed transaction demarcation) for this type of EM?
For example:
It is possible to be a Resource Local EM with Bean Managed Transactions Demarcation? If yes, how can I mark transaction for rollback(I could use: - UserTransaction.rollback(), UserTransaction.setRollbackOnly(), EntityTransaction.rollback(),EntityTransaction.setRollbackOnly())?
Thanks for help
Mario
This message was edited 1 time. Last update was at by Mario Wojcik
Yeray Santana Borges
Ranch Hand
Joined: Mar 02, 2008
Posts: 45
posted
0
Hi Mario,
Yes, you can use an Resource Local Entity Manager with BMT demarcation. BMT is a different demarcation of a JTA transaction, in my examples codes I can't use EntityManager.joinTransaction() for join the Application Manager-Resource Local Entity Manager transaction to the current JTA. I don't know why, but in my examples when I use EntityManager.joinTransaction with Resource Local I get a exception. Maybe somebody can help us.
Persistence specification 5.5.2 Resource Local Entity Managers:
An entity manager whose transactions are controlled by the application through the EntityTransaction API is a resource-local entity manager. A resource-local entity manager transaction is mapped
to a resource transaction over the resource by the persistence provider. Resource-local entity managers
may use server or local resources to connect to the database and are unaware of the presence of JTA
transactions that may or may not be active
I understand that the JTA transaction, in this case with BMT demarcation, is unaware by the EntityManager and due to is a Resource Local it can't join the Resource transaction with the current JTA, for that I see this configuration like independent transactions, once JTA BMT transaction and other a Resource Local Transaction. If you want to rollback the JTA transaction you must use UserTransaction.setRollbackOnly(), if you want to rollback the entity operations you must use EntityTransaction.setRollbackOnly().
This message was edited 2 times. Last update was at by Yeray Santana Borges
SCJP 6 - SCWCD 5 - SCBCD 5
subject: Problem with understanding Transaction Management Demarcation