-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: MappingException - Repeated column error
PostPosted: Tue Oct 02, 2007 5:48 pm 
Newbie

Joined: Tue Sep 11, 2007 9:52 pm
Posts: 7
I am not able to insert record in the child table with following relationship.

Parent table xml mapping
-------------------------------
<hibernate-mapping>
<class name="com.hibernate.PersonContactPo" table="PERSON_CONTACT" schema="ODSCUST_OWNER">
<composite-id name="id" class="com.hibernate.PersonContactPoId">
<key-property name="personId" type="big_decimal">
<column name="PERSON_ID" precision="22" scale="0" />
</key-property>
<key-property name="contactId" type="big_decimal">
<column name="CONTACT_ID" precision="22" scale="0" />
</key-property>
</composite-id>

<set name="contactRelationshipPos" inverse="true">
<key>
<column name="PERSON_ID" precision="22" scale="0" />
<column name="CONTACT_ID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.hibernate.ContactRelationshipPo" />
</set>
</class>
</hibernate-mapping>


Child table xml mapping
----------------------------
<hibernate-mapping>
<class name="com.hibernate.ContactRelationshipPo" table="CONTACT_RELATIONSHIP" schema="ODSCUST_OWNER">
<composite-id name="id" class="com.hibernate.ContactRelationshipPoId">
<key-property name="contactId" type="big_decimal">
<column name="CONTACT_ID" precision="22" scale="0" />
</key-property>
<key-property name="contactMethodId" type="big_decimal">
<column name="CONTACT_METHOD_ID" precision="22" scale="0" />
</key-property>
</composite-id>
<many-to-one name="personContactPo" class="com.hibernate.PersonContactPo" update="false" insert="false" fetch="select">
<column name="PERSON_ID" precision="22" scale="0" />
<column name="CONTACT_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="partyContactPo" class="com.rci.pom.hibernate.PartyContactPo" update="false" insert="false" fetch="select">
<column name="PARTY_ID" precision="22" scale="0" />
<column name="CONTACT_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>


I get the constraint error while hibernate try to insert record into the database. There is a constraint on child table which mandates either of the column PERSON_ID or PARTY_ID should exists but not both during insert.

Below is the Hibernate query from the log
------------------------------------------------
Hibernate: insert into ODSCUST_OWNER.PERSON_CONTACT (PERSON_ID, CONTACT_ID) values (?, ?)
Hibernate: insert into ODSCUST_OWNER.CONTACT_RELATIONSHIP (CONTACT_ID, CONTACT_METHOD_ID) values (?, ?)

From the log it shows only CONTACT_ID, CONTACT_METHOD_ID being inserted and PERSON_ID is not being inserted. I have set inverse="true" at parent table's xml mapping but still the same error. Potential cause of problem i feel is at child table which have attributes update="false" insert="false" which are set in the "many-to-one" tag. If i remove these attributes I get the following error -

Initial SessionFactory creation failed.org.hibernate.MappingException: Repeated
pPo column: CONTACT_ID (should be mapped with insert="false" update="false")


What is the workaround with this relationship ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 12:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
This is not a tools issue. It would be better to ask in the User forum.

Having said that, the relationship should not be able to update the link since its also the primary key, hence insert, update should be false.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.