I am trying to implement a one-to-many association with a assigned String identifier. I have a simple parent child relationship like :
/*** Parent.hbm.xml***/
Code:
<hibernate-mapping>
<class name="org.opcapl.profession.model.Parent" table="parent">
<id column="parent_id" name="id" type="java.lang.String">
<generator class="assigned"/>
</id>
<property column="name" length="255" name="name" type="java.lang.String"/>
<set name="children" inverse="true" cascade="all" lazy="true" >
<key column="parent_id"/>
<one-to-many class="org.opcapl.profession.model.Child"/>
</set>
</class>
</hibernate-mapping>
/*** Child.hbm.xml***/
Code:
<hibernate-mapping>
<class name="org.opcapl.profession.model.Child" table="child">
<id column="id" name="id" type="java.lang.Long">
<generator class="identity"/>
</id>
<property column="name" length="255" name="name" type="java.lang.String"/>
<many-to-one name="parent" class="org.opcapl.profession.model.Parent" column="parent_id" not-null="true"/>
</class>
</hibernate-mapping>
This is exactly the implementation from the hibernate doc except that I have changed the primary key type of the parent table to assigned.
this is not working.
I am trying to do like this :
Code:
Parent parent = new Parent();
parent.setName("parent");
parent.setId("XXXXX");
Child child = new Child();
child.setName("child");
parent.setChildren(new HashSet());
parent.addChild(child);
session.save(parent);
session.flush();
session.connection().commit();
session.close();
I got the following exception :
Code:
Hibernate: insert into child (name, parent_id) values (?, ?)
19:17:48,000 WARN JDBCExceptionReporter:38 - SQL Error: 515, SQLState: 23000
19:17:48,000 ERROR JDBCExceptionReporter:46 - Could not insert NULL value into 'parent_id' column, table 'Dev.dbo.child'. this column does not accpet NULL value. INSERT failed.
19:17:48,000 ERROR JDBCExceptionReporter:37 - Could not insert
this code is working perfectly with an 'indentity' sequence identifier, why it is not working with assigned?
thanks for your help.
S.Shehzad