[jboss-user] [JBoss Seam] - Re: persist() / remove() at end of long running conversation

steve.ebersole@jboss.com do-not-reply at jboss.com
Thu Feb 22 17:12:27 EST 2007

Historically Hibernate would always immediately perform an insert for entities using an IDENTITY based strategy.  The reason was that the Hibernate save() method has a distinctly different semantic from persist(); namely save() requires the generated identifier value to be returned as a return value from the save call!  

persist() is slightly different in that it's declared return type is void, thus the generated identifier does not need to be immediately available upon return from the persist() call.  Thus I changed this behavior starting in 3.2  such that the insertion to generate and obtain the identifier value is delayed until a flush.  However, that only occurs when we are outside a transaction.  This should probably be extended such that we also delay in the case of FlushMode.MANUAL as well.

This should be easy to verify.  Have a look at org.hibernate.event.def.AbstractSaveEventListener#performSaveOrReplicate.  Specifically the part about 'shouldDelayIdentityInserts'.  Currently, that is set via:

  | boolean shouldDelayIdentityInserts = !inTxn && !requiresImmediateIdAccess;

Try changing that to:

  | boolean shouldDelayIdentityInserts = !requiresImmediateIdAccess &&
  |         ( !inTxn || FlushMode.isManualFlushMode( source.getFlushMode() ) );

Let me know how it goes at : http://opensource.atlassian.com/projects/hibernate/browse/HHH-2439

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4020832#4020832

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4020832

More information about the jboss-user mailing list