aspose file tools*
The moose likes Object Relational Mapping and the fly likes UserTransaction in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "UserTransaction in Hibernate" Watch "UserTransaction in Hibernate" New topic
Author

UserTransaction in Hibernate

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I do not understand this (from Hibernate reference guide chapter 3.8.3. Current Session context management with JTA):


Your code can either use JTA programmatically
through UserTransaction, or (recommended for portable code) use the
Hibernate Transaction API to set transaction boundaries. If you run in an EJB
container, declarative transaction demarcation with CMT is preferred.



I have a method in which I need to manage transaction management by myself.

I have a EJB-Container (JBOSS), but I guess, I do not use CMT - I am not sure.

I use JPA with EJB3.0.

So my question, which type should I use to be able to handle Transaction within a Method by myself?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I have a EJB-Container (JBOSS), but I guess, I do not use CMT - I am not sure.

Why don't you know? You are the one who would define this when you wrote the EJB.


So my question, which type should I use to be able to handle Transaction within a Method by myself?

With EJBs you would normally wrap your business logic up in one CMT method call. Where you want have that behaviour, you would deine your EJB method to not support transactions and programatically use JTA. This way Hibernate does not need to change, the session context managmnet remains the same - when you (or the container) starts a new transaction, Hibernate does its thing.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
In general, my EJB is per default CMT. Am I right?

When I want to use BMT, I have to set this explicitly. Am I right?:



My question is, which way should I use, if I want to commit/rollback the update by myself?

I have red a lot but cannot find the straight answer.

Should I use either "EntityTransaction" or "UserTransaction" ?

I guess, I have a JTA transaction, then it would be the first choice to use "UserTransaction" instead of "EntityTransaction", am I right?

Normally, people would suggest using CMP over BMP - should I use CMP and mark the Method update() with TransactionAttributeType.SUPPORTS:





Is this the best way: CMP with TransactionAttributeType.SUPPORTS and UserTransaction?


I do not know, which way I should go.

How does a use of a "bean managed extended persistence contexts" relates to my problem?

I use JPA(Hibernate), JBOSS AS.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UserTransaction in Hibernate
 
Similar Threads
How to Put a Hibernate Session under the App Server's Transaction ?
Stateless SB and Synchronization
Hibernate & J2EE
Hibernate Transactions -- JTA and CMT
Make hibernate use JTA transaction in WAS 5.1