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.  [ 2 posts ] 
Author Message
 Post subject: Changes to bi-directional many-to-many not persisted
PostPosted: Mon Nov 20, 2006 10:27 am 
Newbie

Joined: Wed Jan 04, 2006 5:17 am
Posts: 4
I have two classes Application and BusinessUnit that are related via a many-to-many bi-directional relationship:

In application.hbm.xml:
Code:
<set name="businessUnits" inverse="true" table="ApplicationBusinessUnit">
  <key>
    <column name="applicationId" not-null="true" />
  </key>
  <many-to-many entity-name="com.abnamro.appinv.model.BusinessUnit">
    <column name="businessUnitId" not-null="true" />
  </many-to-many>
</set>


In businessunit.hbm.xml:
Code:
<set name="applications" inverse="true" table="ApplicationBusinessUnit">
  <key>
    <column name="businessUnitId" not-null="true" />
  </key>
  <many-to-many entity-name="com.abnamro.appinv.model.Application">
    <column name="applicationId" not-null="true" />
  </many-to-many>
</set>


The relationship loads correctly from the database, but any attempt to change the relationship does not persist to the database. As an example, creating a new relationship between an existing Application and an existing BusinessUnit does not get persisted even if I add the BusinessUnit to the collection on the Application and add the Application to the collection on the BusinessUnit and explicitly update both the Application and the BusinessUnit within the same session and transaction.

No exceptions are thrown, the update just never seems to happen. I have not included an cascade-on-update to either entity as I only want to change the association, not the objects themselves. Anyone else notice similar behaviour?

Any help would be much appreciated.

Thanks

Mike Horwitz

Hibernate version:
3.2.0

Name and version of the database you are using:
MS SQL Server 8


Top
 Profile  
 
 Post subject: Re: Changes to bi-directional many-to-many not persisted
PostPosted: Mon Nov 20, 2006 12:40 pm 
Newbie

Joined: Wed Jan 04, 2006 5:17 am
Posts: 4
Managed to find a solution. I was using hibernate-tools to generate the mappings from the database which set both side of the relationship to inverse="true".

If changes to the relationship are to be persisted, at least one side must be marked as inverse="false" or have no inverse attribute set (the default for inverse is false).


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