-->
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: Bug with all-delete-orphan and merge
PostPosted: Tue Apr 24, 2007 8:05 pm 
Newbie

Joined: Thu Jan 25, 2007 4:39 pm
Posts: 3
Location: San Francisco
I have some problematic behavior with Hibernate 3.2, and want to ascertain whether this is a bug:

class A {
Set<B> bset;
}
(for this class, the bset relationship is cascade="all-delete-orphan")

a = new A();
session.saveOrUpdate(a);
session.close();

session = hsf.openSession();
a.bset.add(b);
a = session.merge(a);
a.bset.remove(b);
session.saveOrUpdate(a);
session.close();


Most of this works as expected, with the exception that at the end of the code sequence, b is persisted.

b should not be saved since the cascade includes delete-orphan, correct?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 7:50 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
You can apply the following changes to your code,
Replace
>>> a.bset.remove(b);
with
<<< session.flush() ; (1)
<<< a.bset.remove(a.bset.iterator().next()) ; (2)


Reason: (2)
a = session.merge(a) ; would cascade merge to child b ( in a ).
So, the b that we have with us is no longer associated with sesssion ( and with 'a' ).
You can test this. ( a.bset.size() = 1 , even after you remove b, because they are different objects. )

Reason: (1)
I am not clear at this point of time.

I assume that transactions are in place. ( obvious, else you don't expect
data to commit in database )

--------------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 10:48 am 
Newbie

Joined: Thu Jan 25, 2007 4:39 pm
Posts: 3
Location: San Francisco
thanks for the reply pramodkp --

this certainly is a workaround, but actually an easier workaround is to simply to add: session.delete(b) after the call a.bset.remove(b)
I tested this and it correctly deletes the newly created b object.

However, what i'm really asking is whether the code I presented is buggy behavior, because its misleading and seems contrary to the rest of hibernate's behavior.


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.