-->
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.  [ 3 posts ] 
Author Message
 Post subject: flush best practices with deletes in transaction
PostPosted: Wed Jan 11, 2006 2:16 pm 
Newbie

Joined: Wed Jan 11, 2006 2:07 pm
Posts: 2
i am still learning the odds and ends of ORM. I just ran into a problem where i delete some data then re-insert similar data. THe data has a name column which has a unique constraint on it and i am essentially deleting the old data and re-inserting the new data with the same name.

This causes a problem because the inserts are flushed to the db, i think because I am using identity id generation but the deletes are not flushed until the end of the transaction. So the inserts throw a unique constraint violation (on name field) because the delete was not executed first.

I would have assumed that hibernate would automatically flush prior sql calls if it needs to flush the insert call, but i guess it saves the deletes until the very end. So this leaves me in a conundrum. Should I be flushing after every delete in my application? Is there a setting which will automatically do this?

Or am i misinterpreting this situation?

thx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 2:30 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
You can configure when Hibernate does flush. It is explained in the Hibernate reference.
10.10. Flushing the Session

normally you have to flush in seldom cases.
Eg. if you want to get the value from an auto-increment field.

when you use ids generated by the database, your database should not create double entries. You may have another problem here.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 2:50 pm 
Newbie

Joined: Wed Jan 11, 2006 2:07 pm
Posts: 2
LaLiLuna wrote:
You can configure when Hibernate does flush. It is explained in the Hibernate reference.
10.10. Flushing the Session

normally you have to flush in seldom cases.
Eg. if you want to get the value from an auto-increment field.

when you use ids generated by the database, your database should not create double entries. You may have another problem here.

Regards Sebastian


I don't believe I have an additional problem. I am not inserting an additional value with the same id just the same name, and there is a unique constraint on the name. But I delete the old one first. Because hibernate is required to flush the identity inserts when they are called in order to obtain an id it does this immediately however it does not flush the deletes until the end of the transaction per it's performance strategy.

In my mind this doesn't make sense, if it knows it has to complete the sql inserts why not flush everything up until that point. However since it does not my question is what is the best strategy to handle this? Should I just flush after every delete?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.