This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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.
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
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 ]
Joined: Jul 12, 2004
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).