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.  [ 4 posts ] 
Author Message
 Post subject: cascading question
PostPosted: Mon Mar 24, 2008 12:01 pm 
Newbie

Joined: Wed Feb 20, 2008 10:53 am
Posts: 15
Hibernate version: 3.2

A question about cascading . . .

Let's say I have a table "A" which maps to class "A" and
a table "B" which maps to class "B"

Their relationship is one-to-many, that is A can have many B's.

Table and class B contains idA, a foreign key to A.

Now let's say I delete a record from A and I want the corresponding idA in B to be set to null. How should I set the cascade option here?

<bag name="BList">
<key column="idA"/>
<one-to-many class="B"/>
</bag>

Thanks

Eric


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 9:42 am 
Newbie

Joined: Wed Mar 26, 2008 9:04 am
Posts: 9
Location: Athens, Greece
Admittedly Im new to hibernate myself but my guess is, you don't have
to cascade anything. If you modify A (remove the B from the collection) and then flush your session / commit the transaction then I would assume that
B is updated to be removed from A.

Arne


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 2:03 pm 
Beginner
Beginner

Joined: Wed Dec 20, 2006 11:21 am
Posts: 20
It depends on how you design your model. If the relationship is bidirectional, which means that B can only have one parent of type A, then maybe the B object should be deleted from the DB if you delete its parent A.

Or maybe not, which imply that B may not have a parent (in other words, the parent property of B may be null). In this case, you must explicitly detach the B object from its parent A before removing it.

I am not sure just removing the parent will set the parent property of B to null.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 8:09 am 
Newbie

Joined: Wed Feb 20, 2008 10:53 am
Posts: 15
Thanks for the replies!

arne was correct. I acheive the desired outcome by not declaring a cascade and not declaring inverse to be true.


badgerduke


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