• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need many-to-one mapping help

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic