-->
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: Hibernate delete the relationship betwen 2 objects on update
PostPosted: Wed Oct 20, 2004 7:04 pm 
Newbie

Joined: Tue Mar 16, 2004 1:44 pm
Posts: 17
Location: San Jose - Costa Rica
Hibernate version:
2.1.6

Mapping documents:

EmisoTarjeta.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="cr.go.ice.vep.domain" auto-import="true">
<class name="EmisorTarjeta" table="EMISORTARJETA">
<id column="IDEMISORTARJETA" name="idEmisorTarjeta" type="integer" unsaved-value="null">
<generator class="sequence">
<param name="sequence">IDEMISORTARJETA_SQ</param>
</generator>
</id>
<property column="DESCRIPCION" length="25" name="descripcion" not-null="true" type="string" />
<property column="OBSERVACIONES" length="50" name="observaciones" not-null="false" type="string" />
<property column="ESTADO" length="1" name="estado" not-null="true" type="integer" />

<set name="recaudadores" table="RECAUDADOREMISORTARJETA" lazy="true">
<key column="IDEMISORTARJETA" />
<many-to-many class="Recaudador" column="IDRECAUDADOR" />
</set>
</class>
</hibernate-mapping>

Recaudador.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="cr.go.ice.vep.domain" auto-import="true">
<class name="EmisorTarjeta" table="EMISORTARJETA">
<id column="IDEMISORTARJETA" name="idEmisorTarjeta" type="integer" unsaved-value="null">
<generator class="sequence">
<param name="sequence">IDEMISORTARJETA_SQ</param>
</generator>
</id>
<property column="DESCRIPCION" length="25" name="descripcion" not-null="true" type="string" />
<property column="OBSERVACIONES" length="50" name="observaciones" not-null="false" type="string" />
<property column="ESTADO" length="1" name="estado" not-null="true" type="integer" />

<set name="recaudadores" table="RECAUDADOREMISORTARJETA" lazy="true">
<key column="IDEMISORTARJETA" />
<many-to-many class="Recaudador" column="IDRECAUDADOR" />
</set>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Using Spring's HibernateDaoSupport:

public final void modificarEmisorTarjeta(final EmisorTarjeta emisorTarjeta) {
getHibernateTemplate().update(emisorTarjeta);
}

Full stack trace of any exception that occurs:

Name and version of the database you are using:

Oracle 9i

The generated SQL (show_sql=true):

hibernate: update EMISORTARJETA set DESCRIPCION=?, OBSERVACIONES=?, ESTADO=? where IDEMISORTARJETA=?
hibernate: delete from RECAUDADOREMISORTARJETA where IDEMISORTARJETA=?

Debug level Hibernate log excerpt:

EmisorTarjeta has a many-to-many relationship with Recaudador (table EMISORTARJETARECAUDADOR). When i update any information on EmisorTarjeta hibernate delete the relationship (in table EMISORTARJETARECAUDADOR) betwen the two objects

i only want to delete the relatioship if i delete emisorTarjeta

any idea ???

thanks
Ignacio


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 2:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
look at cascade in the reference guide

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 10:10 am 
Newbie

Joined: Tue Mar 16, 2004 1:44 pm
Posts: 17
Location: San Jose - Costa Rica
i have allready read and try all types of cascade (save-update, delete, none) but none of this work .... i really dont know what happend

Thanks
Ignacio


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 12:08 pm 
Newbie

Joined: Tue Mar 16, 2004 1:44 pm
Posts: 17
Location: San Jose - Costa Rica
the problem was that i have to set one side of the many-to-many relationship to inverse="true"

<set inverse="true" name="recaudadores" table="RECAUDADOREMISORTARJETA" lazy="true">
<key column="IDEMISORTARJETA" />
<many-to-many class="Recaudador" column="IDRECAUDADOR" />
</set>

now everything works ok

if you have this problem read

http://www.hibernate.org/155.html

thanks
Ignacio


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.