Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Retrieve CMT transaction in code

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am wondering if it is possible to retrieve a CMT transaction controlled by the container? Say, I have a SessionBean that has "RequiresNew" as the CMT Tx attribute. In my code I would like to get a hold on this transaction - how is this possible?

Thanks for your answers.

D.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by David Follow:
[QB]Say, I have a SessionBean that has "RequiresNew" as the CMT Tx attribute. In my code I would like to get a hold on this transaction



Why? The EJBContext gives you the getRollbackOnly() and setRollbackOnly() methods; what else could you possibly want to do that would not step on the containers toes?

CMT - Container Managed Transaction; i.e. Container: Hands off Bean this is my territory - you just tell me whether or not you can finish your job!

BMT - Bean Managed Transaction; i.e. Container: Fine, fine, micro-manage everything yourself why don't you - I'll even tell my guys to co-operate with you if they can - but don't expect any co-operation from the other square heads like you. (BMT transactions can propagate into a CMT bean (Mandatory,Required,Supported) but not into another BMT bean (no transaction can)).
 
David Follow
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peer,

I am thinkign about something like Hibernate (or equivelent) that needs (or creates) it's own Tx, but I want Hinbernate to use the Tx of the container.
I know that Hibernate has a Factory to retrieve the Tx of the AppServer, so I was just curious how they do it.

D.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate seems to get around that by "handling JTA transparently" (Hibernate in Action). Usually you leave the JTA details to your framework (Spring/Hibernate).

Java Transaction API (JTA)
Bean-Managed Transactions
8.3 J2EE Transaction Technologies
 
David Follow
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bottom line, does this mean that Hibernate somehow uses my J2EE CMT Tx created through the "RequiresNew" attribute?

D.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is suppose so. According to the Hibernate Users FAQ:


How do I use Hibernate with CMT?

Just do it. CMT means neither Hibernate nor user code needs to worry about starting / stopping transactions. You should remember to set hibernate.transaction.manager_lookup_class for your application server.

In a CMT environment, it makes a great deal of sense to use SessionFactory.getCurrentSession(), and leave session management to Hibernate.



For a second opinion you could always pose your question in the Object Relational Mapping forum.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic