I have a class Test4 which owns a collection of Test5's. The collection is implemented as a List. The Test5 class also has a reference back to Test4 so this is a bi-directional one-many association.
When I save an instance of Test4 it saves fine, as do the instances of Test5 in it's collection, but the idx column in the table for Test5 is null after the inserts. This then oviously causes problems when I try to retrieve that instance of Test4.
If I change the association to not be bi-directional and instead have 2 seperate associations, things work fine and the idx column gets the values as expected.
I can't see what the problem is, and whether it's a bug in my code, mapping files or in Hibernate.
Any help much appreciated.
John
Hibernate version:
3.1
Mapping documents:
Mapping file for Parent class. (Test4)
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="ims.testonly.domain.objects.Test4" table="test_test4" lazy="true" discriminator-value="null" >
<id name="id" access="field" type="integer" unsaved-value="null">
<column name="id" sql-type="numeric(10,0)"/>
<generator class="native"/>
</id>
<discriminator not-null="false" length="4"/>
<version name="version" column="vstp" access="field"/>
<property name="isRIE" type="boolean" access="field" update="true">
<column name="rie" not-null="false" unique="false" />
</property>
<component name="systemInformation" class="ims.domain.SystemInformation" access="field" >
<property name="creationDateTime" type="timestamp" access="field">
<column name="sys_creation_datetime" />
</property>
<property name="lastUpdateDateTime" type="timestamp" access="field">
<column name="sys_lastupdate_datetime" />
</property>
<property name="creationUser" type="string" access="field">
<column name="sys_creation_user" length="30" />
</property>
<property name="lastUpdateUser" type="string" access="field">
<column name="sys_lastupdate_user" length="30" />
</property>
</component>
<list name="collt5" inverse="true" access="field" cascade="all-delete-orphan" lazy="true" >
<key >
<column name="t4parent" sql-type="numeric(10,0)" unique="false" />
</key>
<index column='idx'/>
<one-to-many class="ims.testonly.domain.objects.Test5"/>
</list>
<property name="namet4" type="string" access="field" update="true">
<column name="namet4" not-null="false" unique="false" />
</property>
</class>
</hibernate-mapping>
and Mapping for child class, Test5
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="ims.testonly.domain.objects.Test5" table="test_test5" lazy="true" discriminator-value="null" >
<id name="id" access="field" type="integer" unsaved-value="null">
<column name="id" sql-type="numeric(10,0)"/>
<generator class="native"/>
</id>
<discriminator not-null="false" length="4"/>
<version name="version" column="vstp" access="field"/>
<property name="isRIE" type="boolean" access="field" update="true">
<column name="rie" not-null="false" unique="false" />
</property>
<component name="systemInformation" class="ims.domain.SystemInformation" access="field" >
<property name="creationDateTime" type="timestamp" access="field">
<column name="sys_creation_datetime" />
</property>
<property name="lastUpdateDateTime" type="timestamp" access="field">
<column name="sys_lastupdate_datetime" />
</property>
<property name="creationUser" type="string" access="field">
<column name="sys_creation_user" length="30" />
</property>
<property name="lastUpdateUser" type="string" access="field">
<column name="sys_lastupdate_user" length="30" />
</property>
</component>
<many-to-one name="t4Parent" class="ims.testonly.domain.objects.Test4" access="field">
<column name="t4parent" sql-type="numeric(10,0)" not-null="false" unique="false" />
</many-to-one>
<property name="name" type="string" access="field" update="true" >
<column name="name" length="100" not-null="false" unique="false" />
</property>
</class>
</hibernate-mapping>
Name and version of the database you are using:
SQLServer 2000.
The generated SQL (show_sql=true):
Hibernate: insert into test_test4 (vstp, rie, sys_creation_datetime, sys_lastupdate_datetime, sys_creation_user, sys_lastupdate_user, namet4) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into test_test5 (vstp, rie, sys_creation_datetime, sys_lastupdate_datetime, sys_creation_user, sys_lastupdate_user, t4parent, name) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into test_test5 (vstp, rie, sys_creation_datetime, sys_lastupdate_datetime, sys_creation_user, sys_lastupdate_user, t4parent, name) values (?, ?, ?, ?, ?, ?, ?, ?)
As you can see, no mention of the idx column on the Test5 inserts even though it's in the mapping document.
|