-->
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: Integrity constraint violation
PostPosted: Fri Jul 22, 2005 12:05 pm 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Mapping documents:

Code:
<hibernate-mapping package="net.barriault.pdm.model">
   <class name="MfrPart" table="MFR_PARTS">
      <id name="id" type="long" column="ID">
           <generator class="hilo">
                <param name="table">hi_value</param>
                <param name="column">next_value</param>
                <param name="max_lo">100</param>
           </generator>
      </id>
      <natural-id mutable="true">
         <many-to-one name="mfrContact" class="Contact" column="MFR_ID" />
         <property name="mfrPartIdentifier" column="MFR_PART_IDENTIFIER" type="string" />
      </natural-id>
      <list name="history">
         <key column="PARENT_ID" />
         <list-index column="MOD_DATE" />
         <one-to-many class="HistoryItem" />
      </list>
   </class>
</hibernate-mapping>

<hibernate-mapping package="net.barriault.pdm.model">
   <class name="Item" table="ITEMS">
      <id name="id" type="long" column="ID">
           <generator class="hilo">
                <param name="table">hi_value</param>
                <param name="column">next_value</param>
                <param name="max_lo">100</param>
           </generator>
      </id>      
      <natural-id mutable="true">
         <property name="itemIdentifier" column="ITEM_IDENTIFIER" type="string" />
      </natural-id>
      <list name="history">
         <key column="PARENT_ID" />
         <list-index column="MOD_DATE" />
         <one-to-many class="HistoryItem" />
      </list>
   </class>
</hibernate-mapping>

<hibernate-mapping package="net.barriault.pdm.model">
   <class name="HistoryItem" table="HISTORY">
      <id name="id" type="long" column="ID">
           <generator class="native" />
      </id>
      <property name="parentId" column="PARENT_ID" type="long" />
      <property name="action" column="ACTION" type="string" not-null="true" />
      <property name="revisionIdentifier" column="REV" type="string" />
      <many-to-one name="user" class="User" column="USER_ID" />
      <property name="modificationDate" column="MOD_DATE" type="timestamp" not-null="true" />
      <property name="historyItemStatus" column="STATUS" type="string" />
      <property name="details" column="DETAILS" type="string" />
      <property name="comments" column="COMMENTS" type="string" />
   </class>
</hibernate-mapping>


The problem is that the schemaexport is generating two constraints:

Code:
[schemaexport] alter table HISTORY
[schemaexport] add constraint FK620B7074EFBDF662
[schemaexport] foreign key (PARENT_ID)
[schemaexport] references MFR_PARTS;

[schemaexport] alter table HISTORY
[schemaexport] add constraint FK620B7074F6D97C50
[schemaexport] foreign key (PARENT_ID)
[schemaexport] references ITEMS;


And when I try to add history to an Item I get the following SQL error:

Code:
DEBUG: insert into HISTORY (PARENT_ID, ACTION, REV, USER_ID, MOD_DATE, STATUS, DETAILS, COMMENTS, ID) values (?, ?, ?, ?, ?, ?, ?, ?, null)
WARN : SQL Error: -177, SQLState: 23000
ERROR: Integrity constraint violation - no parent FK620B7074EFBDF662 table: MFR_PARTS in statement [insert into HISTORY (PARENT_ID, ACTION, REV, USER_ID, MOD_DATE, STATUS, DETAILS, COMMENTS, ID) values (?, ?, ?, ?, ?, ?, ?, ?, null)]


Any suggestions? I thought about making a superclass that both Item and MfrPart derive from and modifying their mapping files to be joind subclasses, but I'm not sure how to handle the natural id's at that point since joined subclasses don't allow the <natural-id> tag.

Thanks,

JB


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 1:58 pm 
Newbie

Joined: Mon Sep 27, 2004 3:38 pm
Posts: 18
Location: Angleton, TX
Never mind. I found the solution, but in case anybody else needs it . . . change the mapping files to:

Code:
      <list name="history" cascade="all-delete-orphan">
         <key foreign-key="none">
            <column name="PARENT_ID" />
         </key>
         <list-index column="MOD_DATE" />
         <one-to-many class="HistoryItem" />
      </list>


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.