• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Make hibernate use JTA transaction in WAS 5.1

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate version:
2.1.3

Hi guys,
I am concerning how to convert the hibernate-based applicaction between JDBC transaction and JTA transaction transparently. And I have explored the hibernate source code and found out that, if we use a JTA transaction, hibernate will lookup a UserTransaction first and check if there is already another JTATransaction existing. If so, hibernate will not create a JTA transaction and join the existing one. So in this way, hibernate propose to make the application which uses hibernate transaction API can switch between JDBC and JTA transaction even CMT transparently without any code changing.

But in my application, I invode hibernate code in a Container Management Transaction Stateless Session Bean which is configured with Required transaction attribute in WAS 5.1. And in WAS 5.1, if a SLSB is CMT, the container will not provide a user transaction. That means we can't lookup a UserTransaction by "java:comp/UserTransaction". There will be an exception said that there is no comp/UserTransaction in java context. But hibernate does use this way to get JTA transaction. And I know I can configure the JTA transaction lookup name in cfg file, but the "jta/usertransaction" doesn't work with SLSB in WAS either.


So any knows how to make these kind of switching without changing code?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the exact same problem. My jUnit tests work fine. But the minute I attempted to call hibernate inside an ejb, I would get the error. I changed the bean's Transaction Type from container to Bean, and it is now working. Hibernate should handle the transaction piece, so I don't think I'll need to do anything else.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In theory you could create the UserTransaction before the EJB is called and define the EJB method with the "Supports" or "Required" transaction attribute. The EJB would use the same transaction context of the UserTransaction, which would also be available to Hibernate.
[ July 14, 2005: Message edited by: Paulo Salgado ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic