-->
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.  [ 5 posts ] 
Author Message
 Post subject: many-to-many unidirectional
PostPosted: Sun Nov 14, 2004 6:16 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
Hibernate version:2.1

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="model.Utente" table="UTENTI" lazy="true">
<id name="id" column="ID" type="long" unsaved-value="null">
<generator class="native" />
</id>

<property name="ragioneSociale" type="string" />

<property name="username" column="nomeLogin" type="string" />

<property name="password" column="pwd" type="string" />

<property name="email" type="string" />

<set name="utenteNormative" lazy="true" inverse="true">
<key column="IDUTENTE"/>

<one-to-many class="model.Accesso" />

</set>

<set name="normativeSegnate" lazy="true" inverse="true" table="utente_normative_pref" cascade="all">
<key column="IDUTENTE"/>

<many-to-many class="model.Normativa" column="NORMATIVA_ID"/>
</set>

</class>
</hibernate-mapping>






When i try to add a Normativa to the user Hibernate doens't perform any insert in db. Why?

the code is:

HibernateUtil.beginTransaction();
Sesssion session = HibernateUtil.getSession();
session.lock(utente, LockMode.NONE);
utente.getNormativeSegnate().add(normativa);
...
HibernateUtil.commit();
HibernateUtil.closeSession();


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 14, 2004 7:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
inverse=false

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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 14, 2004 9:04 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
thank you. I have inverse="false" now, cascade="all", but when i remove an "normativa" from "utente" with

utente.getNormativeSegnate().remove(normativa);

the sql is like
delete from utente_normative_pref where idutente=?

instead of

delete from utente_normative_pref where idutente=? and normativa_id=?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 14, 2004 9:05 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
cascade="all" doesn't make sense for many-to-many.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 14, 2004 9:08 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
christian wrote:
cascade="all" doesn't make sense for many-to-many.


with save-update the problem is the same.


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