File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Problem with understanding Transaction Management Demarcation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Problem with understanding Transaction Management Demarcation" Watch "Problem with understanding Transaction Management Demarcation" New topic

Problem with understanding Transaction Management Demarcation

Mario Wojcik

Joined: Jan 21, 2010
Posts: 1

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


Yeray Santana Borges
Ranch Hand

Joined: Mar 02, 2008
Posts: 46
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().

Have you tried LearnNowOnline?
subject: Problem with understanding Transaction Management Demarcation