wood burning stoves
The moose likes Object Relational Mapping and the fly likes Need many-to-one mapping help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Need many-to-one mapping help" Watch "Need many-to-one mapping help" New topic

Need many-to-one mapping help

Alfred Akinyemi

Joined: Jan 22, 2008
Posts: 1
<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"/>

<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"/>

<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"/>

<version name="updateVersion" column="update_version" type="long" />

<set name="asnPoAudits" lazy="false" cascade="all-delete-orphan">
<column name="asn_id"/>
<column name="asn_sequence"/>
<one-to-many class="A"/>


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")


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.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Need many-to-one mapping help
jQuery in Action, 3rd edition