These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: DelayedPostInsertIdentifier exception on Hibernate upgrade
PostPosted: Tue Oct 09, 2007 10:57 pm 
Newbie

Joined: Tue Oct 09, 2007 10:48 pm
Posts: 11
Hi,

Since upgrading from Hibernate 3.1.3 to 3.2.5, I'm receiving exceptions in persistence of fields that map to identity columns:

... snip ...

Code:
Caused by: org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type. Expected: class java.lang.Integer, got class org.hibernate.action.DelayedPostInsertIdentifier; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Integer, got class org.hibernate.action.DelayedPostInsertIdentifier
   at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:668)
   at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:408)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
   at org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:752)


This exception only occurs in the following situation:


1. Transaction opened

2. Class is opened via Hibernate:
Code:
getHibernateTemplate().load(entityClass, oid);


3. Entry is added to a mapped list in the class

4. Class is saved via Hibernate:

Code:
getHibernateTemplate().merge(entity);


5. Exception occurs in persistence of entry added in step 3.

Note that this exception doesn't occur when the class is saved as part of a separate transaction from opening.

Looking at the Javadocs for DelayedPostInsertIdentifier, it appears that this should only be present when classes are being persisted outside of a transaction so am unsure why this is happening in this - and only this - situation.

Transaction management in the application is being handled by Spring's TransactionProxyFactoryBean and all methods are set to PROPAGATION_REQUIRED.

We're using JBoss's JTA transaction manager but we are only using JBoss 4.0.1 - is this still supported by Hibernate 3.2?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 11, 2007 12:00 am 
Newbie

Joined: Tue Oct 09, 2007 10:48 pm
Posts: 11
Problem solved.

Did some digging in the Hibernate code - it appears that even though the Spring JTATransactionManager was initialised by the application, Hibernate was falling back to using JDBCTransactionManager because we hadn't explicitly set the transaction manager for Hibernate.

Hibernate's call to see whether it's participating in a transaction was therefore calling the wrong transaction manager, which is returning false.

It does seem odd that from Hibernate 3.1.x to Hibernate 3.2 that the existing JTA transaction manager isn't being picked up - perhaps this should be documented somewhere (if it isn't already?)...

For anyone else in a similar situation, the problem was resolved by setting the jtaTransactionManager property below to reference the application's JTA transaction manager:

Code:
   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="jtaTransactionManager">
         <bean factory-bean="transactionManager" factory-method="getTransactionManager"/>
      </property>
      ...
   </bean>      
      


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.