wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Need many-to-one mapping help" Watch "Need many-to-one mapping help" New topic
Author

Need many-to-one mapping help

Alfred Akinyemi
Greenhorn

Joined: Jan 22, 2008
Posts: 1
<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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need many-to-one mapping help
 
Similar Threads
Problem with Hibernate composite key mapping
Legacy and Hibernate1-2-M Mapping
Many-to-many composite ID
TransientObjectException while fetching data.
Hibernate 3.1