-->
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: Remove object from set
PostPosted: Wed Apr 20, 2005 7:53 am 
Beginner
Beginner

Joined: Sun Mar 28, 2004 9:01 am
Posts: 21
Hello,

I have an n:m mapping between person (Person.class) and group (Gruppe.class). The mapping class is call PersonGruppe.class, so I have a n:1 relation between person and personGruppe and an 1:n relation between personGruppe and gruppe.

Everything works fine if I add a Person to the group and store the group. The problem arises if I want to remove a person from the group.

Hibernate still updates the PersonGruppe relation, but does not remove the complete entry. It only removes the group id:

The person_group table contains the following entry before update:
id person group version
3 1 2 0

after an update of group it contains the following entry:
id person group version
3 1 NULL 0

With Version 2 the complete row were deleted!

Can anyone tell me why this is the case in hibernate3 and how I can configure hibernate to remove the complete row?

Thanks
Rene

Hibernate version: 3.0

Mapping documents:
Person.hbm.xml
<hibernate-mapping>
<class name="at.sozvers.hvb.zustellclient.model.Person"
table="person" lazy="false">
<id name="id" column="id" type="java.lang.Long"
unsaved-value="null">
<generator class="org.hibernate.id.SequenceGenerator">
<param name="sequence">hibernate_sequence</param>
</generator>
</id>
<version name="version" type="java.lang.Long" column="VERSION"
access="property" unsaved-value="undefined" />
<property name="nachname" type="java.lang.String"
column="nachname" not-null="true" />
<property name="titel" type="java.lang.String" column="titel" />
<property name="vorname" type="java.lang.String"
column="vorname" not-null="true" />
<property name="vsnr" type="java.lang.String" column="vsnr"
not-null="true" />
<set name="personGruppeSet" lazy="false"
cascade="all-delete-orphan" sort="unsorted">
<key column="person"></key>
<one-to-many
class="at.sozvers.hvb.zustellclient.model.PersonGruppe" />
</set>
</class>
</hibernate-mapping>


Gruppe.hbm.xml (Group)
<hibernate-mapping>
<class name="at.sozvers.hvb.zustellclient.model.Gruppe"
table="gruppe" lazy="false">
<id name="id" column="id" type="java.lang.Long"
unsaved-value="null">
<generator class="org.hibernate.id.SequenceGenerator">
<param name="sequence">hibernate_sequence</param>
</generator>
</id>
<version name="version" type="java.lang.Long" column="VERSION"
access="property" unsaved-value="undefined" />
<property name="beschreibung" type="java.lang.String"
column="beschreibung" />
<property name="name" type="java.lang.String" column="name"
not-null="true" />
<set name="personGruppeSet" lazy="false"
cascade="all-delete-orphan" sort="unsorted">
<key column="gruppe"></key>
<one-to-many
class="at.sozvers.hvb.zustellclient.model.PersonGruppe" />
</set>
</class>
</hibernate-mapping>

PersonGruppe (Relation between group and person)
<hibernate-mapping>
<class name="at.sozvers.hvb.zustellclient.model.PersonGruppe"
table="person_gruppe" lazy="false">
<id name="id" column="id" type="java.lang.Long"
unsaved-value="null">
<generator class="org.hibernate.id.SequenceGenerator">
<param name="sequence">hibernate_sequence</param>
</generator>
</id>
<version name="version" type="java.lang.Long" column="VERSION"
access="property" unsaved-value="undefined" />
<many-to-one name="gruppe"
class="at.sozvers.hvb.zustellclient.model.Gruppe" cascade="none"
outer-join="auto" column="gruppe" />
<many-to-one name="person"
class="at.sozvers.hvb.zustellclient.model.Person" cascade="none"
outer-join="auto" column="person" />
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
session = getHibernateSession();
tx = session.beginTransaction();
session.saveOrUpdate(persistentObject);
tx.commit();
session.flush();
return persistentObject;


Full stack trace of any exception that occurs:

Name and version of the database you are using: PostgreSQL 8.0

The generated SQL (show_sql=true):
update person_gruppe set gruppe=null where gruppe=?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 10:03 am 
Newbie

Joined: Fri Apr 22, 2005 5:23 am
Posts: 4
I'm getting same problem. Did you figured out what was wrong..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 4:05 pm 
Beginner
Beginner

Joined: Sun Mar 28, 2004 9:01 am
Posts: 21
Yes I found a solution. You have to clear the set so Hibernate knows that it can remove the entries:

Set.clear()

Rene


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.