-->
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: Change order insert delete when modify a list
PostPosted: Thu Jul 03, 2008 12:12 pm 
Newbie

Joined: Mon Sep 24, 2007 10:45 am
Posts: 2
Hi,
I have a problem when I save an object with a list of object mapped.

I change the elements of this list (remove some objects and adds
another ones) and then I save the parent object.

When I save the parent object Hibernate first make INSERT
SQL into database in order to save new objects which I have
added into the list and then make DELETE sql to delete the objects
which I remove from list.

I would like that hibernate could change these operations and
make the DELETE operation before and the INSERT operation
after.

Is it possible? How can I do this?

Thanks a lot for your help.


Enrico


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 8:52 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I'm not sure if you're going to have any success with this.

I believe the inserts are done first for a reason, as the opposite has the potential for violating integrity constraints in certain scenarios.

You might be able to remove the object from the Hibernate Session through an evict, which would stop Hibernate from managing the persistence and doing the inserts first. Then, you could perhaps just do an actual update, or a delete and then an update (although that could be going a little too far.)

For a little bit of background on why Hibernate might be performing those updates, take a look at this little tutorial that goes into How Hibernate Works, and why Hibernate does the things it does.

How Hibernate Works: Understanding the Hibernate ORM Model and Mechanism

Happy Hibernating!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.