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

Hibernate JBoss Transaction

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting the following error in my JBoss 4.0.0 server:

java.lang.IllegalStateException: Transaction has terminated TransactionImpl:XidImpl

I am using Hibernate 2.17c with the JBOss 4.0.0 .har deployer service. I have followed all of the guidelines in King's Hibernate in Action book. I am using the command pattern with a session EJB as it is outlined in the book. The error is thrown right BEFORE the call to the EJB is to end. However, I notice that the data that was to placed in the DB has been persisted. Anyone seen this error or know how to get rid of it?

Thanks
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

java.lang.IllegalStateException: Transaction has terminated TransactionImpl:XidImpl



This exception occurs in EJB,when an attempt is made to either commit a transaction which has been already committed or to start the transaction which has already been started.

The error is thrown right BEFORE the call to the EJB is to end. However, I notice that the data that was to placed in the DB has been persisted. Anyone seen this error or know how to get rid of it?



In your session Bean how are you handling transaction? BMT or CMT ? and how is transaction handled in hibernate? Transaction strategy configuration

The problem might be that in session bean before the method ends, the container or the code(in case of BMT)tries to commit the transaction,but at this stage its already committed by hibernate and that's why the data is persisted in database.
 
Ryan Phelan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, yes, you are correct is it most assuredly some type of trouble with the Hibernate Transaction API and the JBoss EJB transaction manager. I am using CMT. What baffles me is the fact that Hibernate specifies that it is supposed to be working transparently with any App server's transaction. But it seems that it is in error? I am using the following configuration (This is taken from the Getting Started with JBoss 4.0 jboss documentation):

Getting Started with JBoss 4.0[

<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate"
name="jboss.har:service=Hibernate">
<attribute name="DatasourceName">java:/DefaultDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.HSQLDialect</attribute>
<attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
<attribute name="CacheProviderClass">
net.sf.hibernate.cache.HashtableCacheProvider
</attribute>

</mbean>
</server>

Notice that even though the JBossTransactionManagerLookup and JTATrasactionFactory, since it is running as a .har file specific to JBoss, they are loaded implicity. This can be see in JBoss's startup log. It gives INFO messages stating that these two properties have been initiated. Any idea as to how to solve this transaction exception?
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also new to Hibernate and have been reading its documentation and found it this.

Notice that even though the JBossTransactionManagerLookup and JTATrasactionFactory, since it is running as a .har file specific to JBoss, they are loaded implicity.



They are loaded because of the settings in hibernate.cfg.xml file for
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory
</property>
and TransactionManager for jboss in Hibernate is JBossTransactionManagerLookup


According to hibernate documentation , JTATransactionFactory starts its own transaction or continue in previous transaction if already started- in your case session bean transaction. But it does not specify how does it handle the commit part. I mean does it leave commit part on previous transaction to handle it or commit it itself. In your case, it seems to commit the transaction thereby ending it.

So the solution can be to set appropriate transaction ( may be - NotSupported )attribute for session bean method in deployment descriptor for session bean so that session bean is not part of transaction but hibernate start its own new transaction and commit it.
 
Ryan Phelan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A worthy suggestion. I just tried setting the EJB transaction type to notSupported, but this yeiled the following exception

java.lang.IllegalStateException: No transaction.



Here is my command bean (at least the execute method of it anyway):



Hopefully we will be able to resolve this!
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

HibernateUtil.commitTransaction();
}
finally
{
HibernateUtil.closeSession();
}



then may be you delete the statement HibernateUtil.commitTransaction() and use session beans previous Transaction attribute that you were using earlier. or the other way round, i mean keep the session bean's transaction attribute as notsupported but in this execute method begining- use HibernateUtil.beginTransaction() (I am not sure if such method exists in hibernateUtil, i hope it must exist).
 
Ryan Phelan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right. A begin transaction does exist. It is actually being called in the constructor of the DAO. Therefore, a beginTransaction is being called inside of the execute() method. According to hibernate, it is supposed to handle it transparently and use the other transaction that has started (The EJB transaction). I did try removing the commitTransaction and it actually removed the exception! , but then on subsequent calls I get another exception: Already marked for rollback TransactionImpl, which might mean that it has not been commited already, so I put hte commitTransaction in again and removes this new exception, but I get the old one again. . I will keep searching for a way
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Did you find an answer to the problem?

We are using Hibernate on a project and ran into the same issues that u mentioned. The following article posted on java.net might be of interest to you:
http://today.java.net/pub/a/today/2005/01/14/tranhiber.html

As mentioned in this article and as confirmed by the answers posted on Hibernate's faqs, if you use CMT (declarative transaction management by container), then Hibernate has no role to play in transaction management. So calls to Hibernate Transaction api including tx.beginTransaction, commit, rollback etc need not (should not) be made. The container is responsible solely for transaction management.

So I would suggest that u markup the transaction attribute in ur deployment descriptor as required or requiresnew and remove all calls to Hibernate Transaction api.

HTH,

Regards

Prabhakar
 
Whatever you say buddy! And I believe this tiny ad too:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic