views:

36

answers:

0

In the Hibernate reference manual section 11.2.3 it is stated that 'If the Session throws an exception ... rollback the database transaction, call Session.close() and Discard the Session instance'. Do you have any experience or knowledge about what could be the consequences of not following this must? How is this must affected by us using hibernate within an application server with container managed transaction (JBossTS). Does this still have to be taken care of manually?

The reason for the question is that we are basing business logic on unique constraint violations, after which the transaction might be continued on another track. Would this be such a bad idea if it wasn't for this explicit requirement from Hibernate?

My question originates from the fact that we are having some issue with Hibernate and JBossTS. At what seems to be random occurrences, suddenly all sessions that are returned by by the getSession() are associated with an inactive transaction. This is an excerpt from the log, but all the consecutive calls to the server results in this exception and the server would require a restart. Could this be related to not closing the above mentioned sessions?

Exception: org.hibernate.HibernateException 
  Message: Current transaction is not in progress 
As String: org.hibernate.HibernateException: Current transaction is not in progress 

at org.hibernate.context.JTASessionContext:currentSession line: 67
at org.hibernate.impl.SessionFactoryImpl:getCurrentSession line: 544
at com.example.platform.HibernateBaseDAO:getSession line: 51

2009-11-03 09:19:31,642 ERROR [org.jboss.aspects.tx.TxPolicy] IllegalStateException while setting transaction for rollback only
java.lang.IllegalStateException: [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] The transaction is not active!

This specific issue has also been sighted around transaction timeouts, where arjuna will kill the transaction while the the thread that started the transaction will continue to run. When the database returns, the thread will continue it's execution possibly with more calls on the Session. Is this a more probable cause of the cascading 'Current transaction is not in progress' exceptions?