• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Put a Hibernate Session under the App Server's Transaction ?

 
Mrigank Shekhar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My requirement is as follows :

I am using Weblogic 8.1 and Hibernate.

I have a SessionBean. From this Bean I make three create calls to hibernate. Two of the calls should be a part of the Transaction that the Session Bean has started. The third should have its own Transaction and should not be a part of the outer Transaction. Something like the transaction attribute of the third call is REQUIRES-NEW. I would also like the transaction that is started to be a part of the APP server's Transaction and not any other Transaction.

Can you help me out ??

Thanks,
Mrigank.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The third should have its own Transaction and should not be a part of the outer Transaction

In which case (if you are using CMT rather than JTA) you'll need to call it from a SessionBean method which doesn't have a container transaction defined for it.
 
Mrigank Shekhar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:

In which case (if you are using CMT rather than JTA) you'll need to call it from a SessionBean method which doesn't have a container transaction defined for it.


And how do i use CMT rather than JTA . Using a datasource should be enough ??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah sorry you mean a Hibernate Transaction, not a transaction in the container (i.e. even though you are Hibernate in a container, you are using it like it were in a non-managed environment)?

Just commit the transaction after the second create statement, and begin another one for the third call. This will work as you want it to (so long as the Sesison Bean method doesn't use a javax.transaction.Transaction.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic