File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JTA Transaction doesn't rollback Hibernate sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JTA Transaction doesn Watch "JTA Transaction doesn New topic
Author

JTA Transaction doesn't rollback Hibernate sessions

Shanika Weerapperuma
Greenhorn

Joined: Jun 28, 2004
Posts: 26
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 ]
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
Have you included


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

./pope


blog - InfoQ.com
Shanika Weerapperuma
Greenhorn

Joined: Jun 28, 2004
Posts: 26
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

Joined: Jul 12, 2004
Posts: 995
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

Joined: Jun 28, 2004
Posts: 26
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTA Transaction doesn't rollback Hibernate sessions