posted 16 years ago
<hibernate-mapping>
<class name="A" table="tableA">
<composite-id name="aId" class="AId">
<key-property name="poId" column="po_id"/>
<key-property name="asnSequence" column="asn_sequence"/>
</composite-id>
<version name="updateVersion" column="update_version" type="long" />
<many-to-one name="asnAudit" insert="false" update="false">
<column name="asn_id" not-null="true"/>
<column name="asn_sequence" not-null="true"/>
</many-to-one>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="B" table="tableB">
<composite-id name="bId" class="BId">
<key-property name="asnId" column="asn_id"/>
<key-property name="asnSequence" column="asn_sequence"/>
</composite-id>
<version name="updateVersion" column="update_version" type="long" />
<set name="asnPoAudits" lazy="false" cascade="all-delete-orphan">
<key>
<column name="asn_id"/>
<column name="asn_sequence"/>
</key>
<one-to-many class="A"/>
</set>
</class>
</hibernate-mapping>
Notes:
At run-time:
1) rows were successfully inserted into tableB
2) attempt to insert a row in tableA fails with the following error:
Hibernate: insert into tableA (update_version, po_id, asn_sequence) values (?, ?, ?)
08/01/22 09:02:20,603 ERROR [org.hibernate.util.JDBCExceptionReporter] - <ORA-01400: cannot insert NULL into ("tableA"."ASN_ID")
>
08/01/22 09:02:20,619 ERROR [org.hibernate.util.JDBCExceptionReporter] - <ORA-01400: cannot insert NULL into ("tableA"."ASN_ID")
>
Comments:
a) I understand that the insert into tableA fails because of insert="false" update="false" settings in the <many-to-one> mapping.
b) I tried removing insert="false" update="false" from the <many-to-one> mapping of tableA and replace it
with inverse="true" in the <one-to-many> mapping of tableB and got the following error:
org.hibernate.MappingException: Repeated column in mapping for entity: A column: asn_sequence (should be mapped with insert="false" update="false")
Need Help:
I will appreciate anyone with insight on how I might resolve this without falling back to using surrogate keys.
Thanks