-->
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: Prayer for better solution for one-to-many all-delete-orphan
PostPosted: Thu May 26, 2005 7:08 am 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
Dear Hibernate developers, please,
change behaviour of Session.update function with object mapping one-to-many bidirectional with all-delete-orphan.

Don't rely on hibernate implementation of Set to be able to delete orphaned childs from Set owned by Parent.

It is possible to do it relatively easy:
    memorySet = Parent.getChilds()
    loadedSet = select all childs from db for given parent
    for all childs in memorySet that have primaryKey not null do update & remove them from laodedSet
    for all childs in memorySet that have primaryKey null do insert & remove them from loadedSet
    for rest of childs in loadedSet do delete


Thanks very much in advance.

mappings in Parent and Child objects:
Code:
    /**
     * @hibernate.set inverse="true" cascade="all-delete-orphan" lazy="true"
     * @hibernate.collection-key column="parentId"
     * @hibernate.collection-one-to-many class="com.domainmodel.Child"
     */
    public Set getChilds() {
        return childs;
    }


    /**
     * @hibernate.many-to-one column="parentId" class="com.domainmodel.Parent"  not-null="true"
     */
    public Parent getParent() {
        return parent;
    }


keywords:
deleting childs from one-to-many bidirectional relation
how to delete childs from one-to-many bidirectional relation
delete of childs from one-to-many bidirectional relation does not work


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 4:30 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I think below should work:

List list = parent.getChilds();
for (int i=0; i< list.size(); i++) {
Child c = (Child ) list.get(i);
c.setParent(null);
}

saveOrUpdate(parent);

_________________
-developer


Top
 Profile  
 
 Post subject: It is not anwer or solution to my problem
PostPosted: Fri May 27, 2005 4:40 am 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
I don't want to read all childs before update on server side. The bunch comes from client f.e. webservices and deleted childs are simply not present in Set.

To avoid manual programming of loading childs, removing deleted, etc., it must be done directly in Hibernate.


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.