Hi and thanks for your reply,
I think I did not explain our problem correctly.
The Event, Claim and Item objects are all persistent. Both Claim and Item objects have a set of Events (one-to-many relationship with cascade=all), Claim has also a set of Items (one-to-many relationship with cascade=save-update).
So, the problem seems to come from the fact that an Event has (or may have) a double relationship with a Claim and an Item. At the db level, a row in the event table has 2 foreign keys, one pointing to the Claim table and the other to the Item table.
When we try to save a Claim, Hibernate tries to save the whole set of objects related to the Claim (set of items, set of events) but also the set of events related to each item. Hibernate raises an exception while trying to save an event that has the 2 relationships.
We use CBKID as business key, all the equals methods are based on that field. Do we need anything else to tell Hibernate that an event belonging to a claim may belong to an item too.
Any suggestions are welcome :)
Our mappings:
Code:
<class name="Claim" table="CBK_CLAIM">
<id name="id" column="ID" type="java.lang.Long" length="7">
<generator class="native"></generator>
</id>
<property name="cbkId" type="java.lang.Long" update="true" insert="true" column="CBKID" length="12" not-null="true" unique="true"/>
...
<set name="events" lazy="true" cascade="all" sort="unsorted">
<key column="CBK_CLAIMID" foreign-key="CBK_EVENT_CBK_CLAIMID_FK"></key>
<one-to-many class="Event"/>
</set>
<set name="items" lazy="true" cascade="save-update" sort="unsorted">
<key column="CBK_CLAIMID" foreign-key="CBK_ITEM_CBK_CLAIMID_FK"></key>
<one-to-many class="Item"/>
</set>
...
</class>
<class name="Item" table="CBK_ITEM">
<id name="id" column="ID" type="java.lang.Long" length="10">
<generator class="native"></generator>
</id>
<property name="cbkId" type="java.lang.Long" update="true" insert="true" column="CBKID" length="12" not-null="true" unique="true"/>
...
<set name="events" lazy="true" cascade="all" sort="unsorted">
<key column="CBK_ITEMID" foreign-key="CBK_EVENT_CBK_ITEMID_FK"></key>
<one-to-many class="Event"/>
</set>
...
</class>
<class name="Event" table="CBK_EVENT">
<id name="id" column="ID" type="java.lang.Long" length="7">
<generator class="native"></generator>
</id>
...
<property name="cbkId" type="java.lang.Long" update="true" insert="true" column="CBKID" length="12" not-null="true" unique="true"/>
...
</class>