• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

UserTransaction in Hibernate

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Everyone is a villain in someone else's story. Especially this devious tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic