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