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=?
|