-->
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.  [ 4 posts ] 
Author Message
 Post subject: merge and all-delete-orphan
PostPosted: Sun Mar 02, 2008 3:41 pm 
Newbie

Joined: Sun Mar 02, 2008 3:27 pm
Posts: 3
I have a parent class which has a Set of children, the cascade on the one-to-many association is "all-delete-orphan".

When the set of children are changed and session.merge(parent) is called,
it seems that Hibernate first insert new children and then deletes all
children which are not in that set any longer.

For example if Parent A has two children B and C. When B is removed from
Set and a new child (D) is added to the Set of children, and session.merge
is called, first D is inserted and then B is deleted.

The problem is that I want to change the order of these insertions and
deletions.
Is there any solution for this problem?

Thanks


Top
 Profile  
 
 Post subject: Re: merge and all-delete-orphan
PostPosted: Sun Mar 02, 2008 3:44 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
This begs the question of why would you want to do that?


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 02, 2008 4:15 pm 
Newbie

Joined: Sun Mar 02, 2008 3:27 pm
Posts: 3
The scenario is somehow complicated but the abstract is:

We have a client/server application but client is not always connected to server, so clients have their own DBMS. We have used hibernate and MySQL for client-side. The data in client and server is synced each time the user
does the synchronization.

For example suppose we have had a Class A in server (a record in
database), after synchronization this database record is sent to client
and it is persisted by Hibernate. In the next synchronization if A has been
updated, the newer version with all of its dependents (children) will be sent
to client. So those children which do not exist in the new children set,
should be removed and new children must be added to A. But sometimes
because of some DB constraints it causes problems, so I had to remove
children of older version explicitly and then add new children.

I hope I explained the problem clear enough.

Thanks Farzad (Mamnoon)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 02, 2008 4:37 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What is the relation's mapping? I did a test with a many-to-many relation and for me the sequence is:

1- Insert new dependent child.
2- Remove old relation record in the joint table.
3- Insert new relation.
4- Delete old child entry.



In any events, if this is making problems for you then you might want to look into a more manual solution in which a parent entity is loaded first, missing children are removed, session.flush and then merge.


Farzad-


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