-->
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.  [ 5 posts ] 
Author Message
 Post subject: Orphan Deletion and new collections
PostPosted: Thu Oct 12, 2006 7:16 pm 
Newbie

Joined: Wed Jul 26, 2006 9:53 pm
Posts: 16
Hibernate version:
3.0.5

I am facing a problem with orphan deletion. As long as the application is working with the hibernate-modified collection instance the orphan-deletions happen correctly but if the user replaces the old collection a brand new collection then the collection table gets updated correctly but the orphaned elements (from the old collection) do not get removed from the database.
I came across acouple of posts that had similar issue but in their application they could get away by not creating a new collection but clearing the old one and repopulating it but for me this is not an option as Hibernate is being used remotely and i cannot control the client-side input.
So there would be scenarios where they would be working with the original reference (which they did save but due to the fact that the application runs remotely the Hibernate's modification to the collections is not visible on the client-side and hence if the user updates the original reference then the collection again doesnt have the Hibernate changes.
Idealy Hibernate should be able to recogonize the orphans even if this is not teh originally modified collection. To me the orphan-deletion implementation seems to be incomplete. It works only in limited situations. Anyways it was broken for one-to-one references and was only working for collection references and now it seems that that too is not gurateed to always work.
Does anyone has any suggestions to solve this problem elegantly and does in near future Hibernate plans to provide a more complete implementation of orphan deletion?
I would really appreciate any suggestions on solving this issue. Since I am using Hibernate to manage ORM I really dont want to manage the orphans in my application code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 8:27 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Ranjee29,

One option is to remove the control over the map from the client side. Instead of returning the map object through a getter provide an api that allows to add/remove children. You may need to return a facade object instead of the real hibernate object.

Another approach is to clone the map into a private object when sending the object over the fence and compare the content of the map when the object comes back. Throw an exception if you can get away with it ;)

If this is not an option you can just find all the orphans in the database and delete them. This can be done with left join query outside of hibernate and would be similar in principle to the garbage collection philosophy in java: don't bother the programmer with things that the computer can handle.

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 13, 2006 2:26 pm 
Newbie

Joined: Wed Jul 26, 2006 9:53 pm
Posts: 16
mseritan wrote:
Ranjee29,

Another approach is to clone the map into a private object when sending the object over the fence and compare the content of the map when the object comes back. Throw an exception if you can get away with it ;)

Marius


Well I really dont want to make the Hibernate changes visible on the client-side unless the client has made some fetch request to the server, as this would imply that I have to send back all the inserted objects back on to the client-side and somehow merge this state with the original state of objects on the client-side (which I might not have access to) and also the application does bulk inserts at times for which this solution is even worse.

And also i dont want to do a DB cleaning at scheduled times as that again would not fit into our applications expected functionality, and also there can be too many relationships that can potentially produce orphans.

But anyways thanks a lot for your suggestions. :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 13, 2006 5:39 pm 
Newbie

Joined: Thu Aug 10, 2006 12:25 am
Posts: 13
Why not take back a set of the children that you want and use the set function to remove all but those children.


Orginal set is cloned and sent to the caller.
Or/then

the caller returns a set of children that he wants.

original set.retain (set returned by the caller).

Then hibernate should see all the removeall's and then delete the orphaned children


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 5:58 pm 
Newbie

Joined: Wed Jul 26, 2006 9:53 pm
Posts: 16
Well I cannot send back the original set till the user explicitly asks for them. Everything if the user first retrieves the object and then works with the retrieved object, but if he just saves the object and then works with the original reference (that doesnot have the hibernate-modified collecton) and later in a new session updates this reference then orphan deletion fails.
Hence problem occurs only in this specified scenario.


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