-->
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: Deleting from bidirectional relationships
PostPosted: Fri Dec 09, 2005 6:30 am 
Newbie

Joined: Fri Dec 09, 2005 6:17 am
Posts: 7
If I have the following arrangement

Code:
public class Target {
   
    Target target;
    Set targets = new HashSet();
   
    public void addTarget(Target target) {
         targets.add(target);
         target.add(this);     
    }
    pubilic void removeTarget() {
         targets.remove(target);
         target.remove(this);
    }

}


If the set of targets are loaded lazily, is it possible to delete a Target without first loading all the other targets that it references into session i.e. is there a single query that could delete the object and unhook it from all of it's targets?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 1:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
do child.setParent(null);

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Clarification
PostPosted: Mon Dec 19, 2005 7:38 am 
Newbie

Joined: Fri Dec 09, 2005 6:17 am
Posts: 7
OK, I'm obviously not being clear enough about my query so let me try again.

In jdo2 there is a feature called dependent fields. Using this feature with collections it is possible to declare that an object should only remain in a collection so long as there is a reference to it elsewhere in the system. For instance if I ask the persistenceManager (equivalent of session) to delete an object then it will be automatically removed from all collections that have declared themselves as being dependents.

It is this behaviour that I am trying to replicate using ejb3. Currently when I delete an object I have to manually remove it from any collections which maintain a reference to it. This requires loading the objects which hold the collections which in my current scenario can involve loading a large amount of data. Is there any way to replicate this behaviour, perhaps using a hibernate extension ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 7:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This feature is not provided neither in EJB3 not in Hibernate.
This no the way you would work in a plain OO model. This requires bytecode enhancement and does not work nicely with detached objects.
You can try collection lazy="extra" in your specific case.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 7:07 am 
Newbie

Joined: Wed Nov 30, 2005 5:18 am
Posts: 3
You can use not-found="ignore" in one-to-many collection mapping


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.