-->
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: many-to-one cascade=all-delete-orphan emulation?
PostPosted: Wed Nov 10, 2004 8:26 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
Hibernate version:
2.1.6

Situation, two classes A and B.
A contains a B as a property.
A.getB() or similar.

PseudoCode:
A a = hibernate.get(A.class, some identifer);
B b = a.getB(); // B's are unique to A, lifecycle entirely dependent on A
// now I want to replace the b on that a object
a.setB(NULL);
a.setB(new B());
hibernate.save(a);

Now what its currently doing is inserting the new b and pointing a to it. However the old b becomes dereferenced and just floats in the database. What I WANT it to do is be deleted since its nolonger referenced by an A. Is this possible? (seems to me i need a cascade="all-delete-orphan" for many-to-one's, but that doesnt exist).

code snippet:
Code:
        <many-to-one
            name="data"
            class="com.dailydose.content.management.model.FileData"
            cascade="all"
            outer-join="false"
            update="true"
            insert="true"
            access="property"
            column="FILEDATA_ID"
            unique="true"
        />


Thanks!
David


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 11, 2004 3:24 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Guess you're using a one-to-one on the A side.

As a work around use a bag/list/set/... on the one side and use cascade="all-delete-orphan"
If you prefer hide the fact of the collectino/array behind accessor methods which set/get only one instance into the collection/array. You have to set the access="field" for that.

HTH
Ernst


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.