I am in the process of migrating to hibernate3, but I'm currently experiencing a problem in hibernate2. If there is another location I should be going, please let me know.
I'm working with two model objects with independent lifecycles: Agreement and Committee respectively. I am creating a CommitteeAssignment many-to-many entity object to save the following:
Code:
committee_assignments
-----------------------------
agreement_id
committee_id
term_start
term_end
...
Saving one CommitteeAssignment goes all the way to the db, no problems. When I add another and try to save, the transaction attempts to insert both, causing a duplicate key violation.
My setup seems to cause Hibernate not to see the first saved CommitteeAssignment as persistent. I verified by saving the first, and them re-attaching the Agreement object graph with a session.lock() and i got a "cannot lock tranisient instance: CommitteeAssignment" (please NOTE that the object was already saved through to the database.
Here are the players:
in Agreement.hbm.xml....
Code:
<set name="committeeAssignments" lazy="true" inverse="true"
cascade="all-delete-orphan">
<key column="agreement_id"/>
<one-to-many class="........CommitteeAssignment"/>
</set>
in CommitteeAssignment
Code:
<composite-id name="id" class="........CommitteeAssignemt$Id"
unsaved-value="any">
<key-property name="agreementId" column="agreement_id"/>
<key-property name="committeeId" column="committee_id"/>
</composite-id>
<many-to-one name="agreement class="........Agreement"
column="agreement_id" insert="false" update="false"/>
<many-to-one name="agreement class="........Committee"
column="committee_id" insert="false" update="false"/>
In Committee is the same as in agreement, but with key column of "committee_id"
Thanks in advance.