Hi, I'm having problem with the following hibernate mapping, and hoping someone could suggest a solution or a way to work around it.
Code:
<hibernate-mapping>
<class name="xyz.OwnerOneBO" table="OwnerOneBO">
<id name="id" column="id" type="string"><generator class="assigned"/></id>
<version column="version" name="version" type="long"/>
<list name="positionList" cascade="all">
<key column="OwnerOne_positionList_FK"/>
<index column="positionList_index"/>
<element type="adi.gme.datamodel.type.PositionHBType">
<column name="positionList_x" />
<column name="positionList_y" />
<column name="positionList_z" />
</element>
</list>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="xyz.OwnerTwoBO" table="OwnerTwoBO">
<id name="id" column="id" type="string"><generator class="assigned"/></id>
<version column="version" name="version" type="long"/>
<list name="positionList" cascade="all">
<key column="OwnerTwo_positionList_FK"/>
<index column="positionList_index"/>
<element type="adi.gme.datamodel.type.PositionHBType">
<column name="positionList_x" />
<column name="positionList_y" />
<column name="positionList_z" />
</element>
</list>
</class>
</hibernate-mapping>
Using the above mappings I end up with a table called "positionList", and it has six columns namely:
OwnerOne_positionList_FK,
positionList_index,
positionList_x,
positionList_y,
positionList_z,
OwnerTwo_positionList_FK
When I create an instance of OwnerOneBO and added a Position object to the positionList attribute I get the following exception:
net.sf.hibernate.JDBCException: Could not synchronize database state with session: Try to insert null into a non-nullable column in statement [insert into positionList (OwnerOne_positionList_FK, positionList_index, positionList_x, positionList_y, positionList_z) values ('E0ED0A1C-9B62-7A0A-82F7-27CA9A21CD08', 0, 0.0E0, 0.0E0, 0.0E0)]
In other words, it's complaining that I didn't specify "OwnerTwo_positionList_FK" column. But that was indeed my intention to leave the "OwnerTwo_positionList_FK" column as null when the positionList created belongs to OwnerOneBO.
Apart from giving the two list elements distinctive names. Does anyone know if there is property I can set to tell Hibernate to ignore "OwnerTwo_positionList_FK" when I create an instance of OwnerOneBO. Or does anyone know any other way to work around this
issue?
Regards,
KC