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: many-to-many deleting only relationship
PostPosted: Tue Aug 10, 2004 8:07 am 
Senior
Senior

Joined: Wed Sep 24, 2003 3:01 pm
Posts: 158
Location: Bragan�a Paulista - Brasil
Hi,

I have a relationship many-to-many betwwen Manager and Responsible

Hibernate version: 2.1.4
Name and version of the database you are using: Oracle 9i

Mapping documents:

// Manager

<hibernate-mapping>
<class name="proj.register.ManagerTO" table="gestor">
<id name="idManager" column="id_gestor">
<generator class="assigned"/>
</id>
<property name="naManager" column="no_gestor"/>
<bag name="responsibles" table="gestor_x_responsavel" lazy="false" cascade="all">
<key column="id_gestor"/>
<many-to-many class="proj.register.ResponsibleTO"
column="id_responsavel"/>
</bag>
</class>

</hibernate-mapping>


// Responsible

<hibernate-mapping>
<class name="proj.register.ResponsibleTO" table="responsavel">
<id name="idResponsible" column="id_responsavel">
<generator class="assigned"/>
</id>
<property name="naResponsible" column="no_responsavel"/>
<bag name="managers" table="gestor_x_responsavel" inverse="true" lazy="false" cascade="all">
<key column="id_responsavel"/>
<many-to-many class="proj.register.ManagerTO" column="id_gestor"/>
</class>
</hibernate-mapping>



when I try execute the session.delete(manager),
it is deleted the relationship and the responsible objects too,
but I need delete only the relationship between the manager and resposible.

How can I do this???

thanks!!

_________________
Tads


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 8:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
manager.getResponsibles().remove(responsible)
responsible.getManagers().remove(manager)


Top
 Profile  
 
 Post subject: many-to-many association update
PostPosted: Tue Aug 10, 2004 2:31 pm 
Newbie

Joined: Tue Aug 10, 2004 2:25 pm
Posts: 1
In the example of many-to-many association(manager-responsible), anther table will be generated when exportschema(say Manager-responsible), with two forgeign key to ids of them, and the two foreign combine as the key.

For below deletion: is it one SQL or two, if two, it seems that the not-null constraints will be violated?
manager.getResponsibles().remove(responsible)
responsible.getManagers().remove(manager)

It seems tricky for many-to-many association because the relationship table is not assocaited with a persistent class, is there other decent alternatives for this mappying.

Thanks


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.