-->
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: Flush within a flush via post-insert event?
PostPosted: Thu Jun 22, 2006 5:03 pm 
Newbie

Joined: Thu May 18, 2006 10:00 am
Posts: 12
If anyone can shed some light on this, it would be greatly appreciated.

Does anyone know how hibernate behaves when session.flush is called within a session.flush? We are currently using the post-insert event which in turn ends up calling a flush.

For instance, the scenario is this:
1. Create an aggregate of entities
2. Call session.save
3. Call session.flush
4. An entity is persisted
5. The post-insert event fires
6. The post-insert event calls a DAO which does a session.flush

This is resulting in duplicate insert statements for one of the entities in the object graph and thus db constraint violations.

My theory is that since the second flush is within the first flush the queued DML is never marked as completed and hibernate tries to run it again. Any thoughts out there?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 7:29 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You are correct. You are not allowed to do this. You may open a different sesesion inside your event or interceptor methods, and use that to save, but you may not use the current session to do anything while inside an event or interceptor method. About the only useful thing the current session can do at this point is the Session.getIdentifier() method.

_________________
Code tags are your friend. Know them and use them.


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.