I'm using hibernate 3.1 cr2
I'm using a one-to-one mapping where the 'child' table has a PK which is also a FK to the 'parent' table. So I have a constrained one-to-one mapping. The 'child' table has an id that looks like:
Code:
<id name="id" column="ad_id" type="long">
<generator class="foreign">
<param name="property">placement</param>
</generator>
</id>
<one-to-one name="placement" class="PlacementImpl" constrained="true" />
Everything works fine for inserts and deletes, but fails on updates. Updates fail because Hibernate tries to insert into the 'child' table again instead of knowing to update. I don't know how to tell Hibernate that an update is occurring instead of an insert.
What do I need to do to get updates to work? Thanks in advance...
The two simplified mapping file are below:
Placement.hbm.xml
Code:
<class name="PlacementImpl" table="PLACEMENTS" dynamic-update="true">
<id name="id" column="ID" unsaved-value="-1" type="long">
<generator class="sequence">
<param name="sequence">PLACEMENTS_SEQ</param>
</generator>
</id>
<one-to-one name="userListExpression" class="UserListExpressionImpl" access="field" cascade="all" />
</class>
UserListExpression.hbm.xml
Code:
<class name="UserListExpressionImpl" table="placement_filter_expression">
<id name="id" column="ad_id" type="long">
<generator class="foreign">
<param name="property">placement</param>
</generator>
</id>
<one-to-one name="placement" class="PlacementImpl" constrained="true" />
</class>