• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTA Transaction doesn't rollback Hibernate sessions

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

Name and version of the database i am using : Oracle 8

JBoss : V4.0.0

I have configured Hibernate in JBoss through .har deployer and get the session by the JNDI to the session factory. All working fine except for Transactions.

I use JTA and have given my Transaction demarcation in the deployment descripter of my stateless session bean as :





Ideally i need the container to rolback the transaction if anything goes wrong withing the method "executeProcess", which does not happen currently in my application. In that method, i call session.save method several times, but if one save operation fails, it doesn't rollback all the other save operations, which is want i'm trying to acieve.

I understand that when the :



- gets called several times withing the same transaction, the sessions used get bound to the current context which means to the current JTA transaction. Then why won't the transaction gets rolled back with all the save commands that took place?

Am i missing something in my JBoss JTA configurations? If so can anyone give me some hints on configuring JTA on JBoss.

Thanks alot for considering my issue.

[ November 16, 2004: Message edited by: Shanika Weerapperuma ]
[ November 16, 2004: Message edited by: Shanika Weerapperuma ]
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you included


in your ejb-jar.xml for each session bean?

./pope
 
Shanika Weerapperuma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Ali,

yes this is specified in my ejb-jar of my session bean.


I still could not find the solution but i got this piece of infor when i did some reading and hope if anyone could give me a clariffication on this.
according to http://java.sun.com/j2ee/1.4/docs/tutorial/doc/ :


Rolling Back a Container-Managed Transaction

There are two ways to roll back a container-managed transaction. First, if a system exception is thrown, the container will automatically roll back the transaction. Second, by invoking the setRollbackOnly method of the EJBContext interface, the bean method instructs the container to roll back the transaction. If the bean throws an application exception, the rollback is not automatic but can be initiated by a call to setRollbackOnly.



and according to Enterprise JavaBeans, 4th [O'Reilly-2004].chm

System exceptions are java.lang.RuntimeException and its subtypes, including EJBException. An application exception is any exception that does not extend java.lang.RuntimeException or java.rmi.RemoteException.



Does this mean that HibernateException s will never get automatically rolledback by the JBoss container since it's not a sub type of RuntimeException?

Well it seemed like that. I wrapped my Hibernate exceptions in one of my own exception class that extends from RuntimeException and it worked. But i'd like to know how this must be handled properly since this is not an elegant solution.

please help
[ November 17, 2004: Message edited by: Shanika Weerapperuma ]
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shanika... I did forget to tell you about this. Indeed a runtime exception is the only automatic way to roll back a transaction. In my applications I always wrap hibernate exceptions in runtime exceptions (the Hibernate guys will provide also this solution directly in Hibernate in the 3.0 version).

./pope
 
Shanika Weerapperuma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic