Hi there
I have 2 tables
tblParent
parentID - primary key
description
tblChild
parentID - primary key +
childID - primary key ( composed)
description
Code:
<hibernate-mapping>
<class name="mypackage.Parent" table="tblParent">
<id name="parentID">
<column name="pk_iParentID" sql-type="integer"/>
<generator class="native"/><!-- ADDED AFTER -->
</id>
<property name="description">
<column name="szDescription" not-null="false" sql-type="varchar(100)"/>
</property>
<set cascade="all, delete-orphan" inverse="true" name="reference2Child">
<key>
<column name="pkfk_iParentID" not-null="true"/>
</key>
<one-to-many class="mypackage.Child"/>
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="mypackage.Child" table="tblChild">
<composite-id class="mypackage.ChildPK" mapped="true">
<key-property name="parentID">
<column name="pkfk_iParentID" not-null="true" sql-type="integer"/>
</key-property>
<key-property name="childID">
<column name="pk_iChildID" not-null="true" sql-type="integer"/>
</key-property>
</composite-id>
<property name="description">
<column name="szDescription" not-null="false" sql-type="varchar(100)"/>
</property>
</class>
</hibernate-mapping>
I've lost two days trying to convince hibernate to automatically generate parentID (incremental or sequencial - not important) but it seems to be impossible.
Normally is enough to just create a new object of type Parent with parentID null and persist it in db. then hibernate will generate parentID automatically. and it works but only in case that parent hasn't children.
if object parent to be persisted has reference to children then hibernate will throw error:
"column 'pkfk_iParentID' in table 'tblChild' cannot be NULL"More of that , i tried to add reference many-to-one from children to parent ( although i don't need it and will bring me a lack of performance) but still without success; hibernate get error from JDBC
"JZ0SB: Parameter index out of range"I don't know what to think anymore, this is a issue in hibernate's garden or i do something wrong. I red thousands post but i didn't found any helpful clue.
I'm running out of time and i tending to reach desperation.
Many thanks in advance for any advice that can give me/
Best regards
grandanat