Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UserTransaction in Hibernate

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic