aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes UserTransaction and EntityTransaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "UserTransaction and EntityTransaction" Watch "UserTransaction and EntityTransaction" New topic
Author

UserTransaction and EntityTransaction

Tang Yue
Ranch Hand

Joined: Nov 11, 2008
Posts: 40
UserTransction manages JTA transactions while EntityTransction is responsible foir resource-local transactions.
What if this happens:
ut.begin();
et=em.getEntityTransaction();
et.begin(); // what happens here? an IllegalStateException? Or the outer transaction is suspended?
...


Houston Rockets go go go!
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Im not 100% sure. But I think this is illegal. Because nested transactions not allowed.
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
That shouldn't be a problem: JTA transactions and entity transactions don't influence each other (see core spec. 13.3.3, footnote 63).
[ November 21, 2008: Message edited by: Ralph Jaus ]

SCJP 5 (98%) - SCBCD 5 (98%)
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
JTA Transactions and User Transactions :roll: User Transactions are also JTA Transactions.
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Yeah In the first version I had writen "JTA transactions and user transactions" instead of "JTA transactions and entity transactions". I corrected the mistake as fast as I could, but no chance, Chaminda was faster
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Its ok Ralph....

But problem is still remaining. the section you pointed was not much helpful

Do you think this is possible?
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Hi Cham,
Do you think this is possible?
Yes, see for example Pro EJB 3 chapter 5, page 130:
Resource transactions [= entity transactions, remark from me] may be freely started and committed any number of times within a JTA transaction without impacting the state of the JTA transactions.
This can be used for example to decouple persisting log entries from committing resp. rolling back the business transactions.

I also tried this example with starting and committing an entity transaction within a JTA transaction that will be rolled back. Worked as expected: The business data were not in the database while the log entries are.
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Thanks Ralph for the infor
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UserTransaction and EntityTransaction
 
Similar Threads
transaction handling in ejb2.0
web application concurrent access
Transactions in swing
disabling autoCommit in hibernate
Invoking commit() from CM transactions