-->
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: Deleting the m2m link, not the entity
PostPosted: Tue Nov 29, 2005 11:50 am 
Newbie

Joined: Wed Aug 10, 2005 6:26 am
Posts: 8
hello,
I use hibernate3 and I have mapped a bidirectionnal many-to-many relationship: A *--------------* B
In database, I have:
A(idA), B(idB) and AB(idA, idB)

How can I delete the link AB without deleting A or B

For example, I would like to delete A, and delete cascade from AB but not to delete B. I there any solution to do this, without entity class AB?

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 2:35 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
either pass an instance of AB to Session.delete or

call A.setB(null) // or at least the
call B.setA(null) // owning side
Session.update(A)
Session.update(B)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 5:11 pm 
Newbie

Joined: Wed Aug 10, 2005 6:26 am
Posts: 8
you can't pass an instance to AB because AB is not a Class or an entity!

and if I set: A.setB(null) --> it deletes B AND AB
I want to delete only the link AB


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 5:57 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
are you doing anything with the cascade attribute in mapping docuements?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 6:20 pm 
Newbie

Joined: Wed Aug 10, 2005 6:26 am
Posts: 8
Collaborateur *-------------------RESSOURCE_PROJECT---------------* Project

In Ressource
Quote:
<set name="projetsAssignes" table="RESSOURCE_PROJET" cascade="none" >
<key column="refRessource" />
<many-to-many column="refProjet" class="Projet" />
</set>


and in Projet
Quote:
<set name="ressourcesDisponibles" table="RESSOURCE_PROJET"
cascade="none" inverse="true">
<key column="refProjet" />
<many-to-many column="refRessource" class="Ressource" />
</set>


so there are only two entities
When i delete a Project, I would like to delete the references in table RESSOURCE_PROJECT but not to delele the Ressource
because the lifecycle of a ressource is not linked to a project


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 6:37 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
mauvais_karma wrote:
and if I set: A.setB(null)


... you have two sets, so wouldn't this be Set.remove rather than passing null to a setter?


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.