-->
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.  [ 6 posts ] 
Author Message
 Post subject: many to many cascade values???
PostPosted: Wed Oct 06, 2004 7:49 am 
Newbie

Joined: Wed Oct 06, 2004 3:20 am
Posts: 12
Hi!

I have a problem.:-) i have a many-to-many assosiation between user and Flavour means a user can tell us which flavours he likes( vanilla, chocolat etc.)
now if i delete my user, i would like to delete his entry in the table User_flavour.. but logically i dont want to delete my flavours in my flavours table...

how can i solve that?

i think i have to find the correct cascade values...but which one ...:-)

Thanks a lot!

User.hbm.xml

<set name="flavours" table="user_flavour" cascade="all">
<key column="u_id"/>
<many-to-many class="criteria.Criteria" column="criteria_id"/>
</set>

Flavour.hbm.xml

<set name="users" table="user_flavour">
<key column="flavour_id"/>
<many-to-many class="user.User" column="u_id"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 8:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Use the "all" cascade style. In Hibernate2 it is not possible to cacade across a many-to-many such that the "far entity" is deleted. "all" will simply remove the row from the association table.


Top
 Profile  
 
 Post subject: cascade doesnt works
PostPosted: Wed Oct 06, 2004 9:31 am 
Newbie

Joined: Wed Oct 06, 2004 3:20 am
Posts: 12
I tried it with cascade="all" in my set on user side, but it delets the flavours of my user, the flavours in my flavour table and in the table user_flavour all entries, that have the same flavour like my user...*sniff*:-)

is it correct, that it doesnt depend on which "side"( flavour or user) i place the cascade property?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 7:58 am 
Newbie

Joined: Thu Apr 28, 2005 10:25 am
Posts: 7
Location: Italy
hi everyone.
i' ve got the same problem, but with a slightly different mapping of the many-to-many relationship: in fact i used an idbag to realize a unidirectional many to many relationship from father to children, allowing multiple instance of the same child to be added and treated correctly in the collection.
here it is the mapping i' ve got (i' ve changed class names for better comprehension ):
-> Hibernate 2.1.6 <-


<class name="Father" table="father" mutable="true">
<id name="id" column="fat_id" type="java.lang.Integer" >
<generator class="native">
......
</generator>
</id>
......
<idbag name="children" table="father_son" lazy="false" outer-join="true" cascade="all" >
<collection-id type="java.lang.Integer" column="fat_chi_id">
<generator class="hilo">
</generator>
</collection-id>
<key column="fat_id"/>
<many-to-many column="chi_id" class="Child" outer-join="true"/>
</idbag>
</class>

<class name="Child" table="child" mutable="true">
<id name="id" column="chi_id" type="java.lang.Integer" >
<generator class="native">
.......
</generator>
</id>
.........
</class>

well, as previously reported, a delete command called on a Father persistent object actually remove both the link table entries and the "child" table ones.
I think this is an unwanted behavior, isn' t it?
I appriciate further contribution.
Thanks.

_________________
~ Luca Ghirotti ~
Technology Reply


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 8:11 am 
Newbie

Joined: Thu Apr 28, 2005 10:25 am
Posts: 7
Location: Italy
here i go again.
i' ve found ( maybe already well-known from ages :D ) that the desired behaviour may be obtained from the previous mapping just by changing the cascade of the many-to-many collection from "all" to just "save-update".
hibernate itself will eliminate just the father and his entries in the link-table, leaving all the child up and running in their own table.

Hope that can help someone.
See ya.

_________________
~ Luca Ghirotti ~
Technology Reply


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 8:24 am 
Newbie

Joined: Wed Jun 01, 2005 8:20 am
Posts: 1
Same problem here. I already discovered the cascade="save-update" option. But, when i try to delete a Flavour i get a database error. Apparently the Flavour is deleted, but the associated records in the UserFlavour table are not. When i delete a User the associated records in the UserFlavour are deleted.

Is it possible to use an unidirectional many-to-many and be able to delete both sides of the many-to-many?


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