i used default uuid generators take a look :
MAPPING
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="test.hibernate.Child" table="Child1">
<id type="string" unsaved-value="null" >
<column name="child_id_child" sql-type="varchar2(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="childName">
<column name="childName" sql-type="char(30)" not-null="true"/>
</property>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="test.hibernate.Parent" table="Parent1">
<id type="string" unsaved-value="null" >
<column name="parent_id_parent" sql-type="varchar2(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="parentName" access="field">
<column name="ParentName" sql-type="char(30)" not-null="true"/>
</property>
<set name="children">
<key column="CHILD_ID_PARENT"/>
<one-to-many class="test.hibernate.Child"/>
</set>
</class>
</hibernate-mapping>
Tables : Code:
SQL> desc child1
Name Type
---------------------------- --------
CHILD_ID_CHILD CHAR(32)
CHILD_ID_PARENT CHAR(32)
CHILDNAME CHAR(30)
SQL> desc parent1
Name Type
--------------------------- ---------
PARENT_ID_PARENT CHAR(32)
PARENTNAME CHAR(30)
CLASSES:Code:
public class Parent {
public String parentName;
public Set children = new HashSet();
public void addChild(Child child) {
this.children.add(child);
}
public Set getChildren() {
return children;
}
public void setChildren(Set children) {
this.children = children;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
}
public class Child {
private String childName;
public String getChildName() {
return childName;
}
public void setChildName(String childName) {
this.childName = childName;
}
}
RUNNING :Code:
Child child = new Child();
child.setChildName("Child");
Parent parent = new Parent();
parent.setParentName("Parent");
parent.addChild(obj);
sess.save(child);
sess.save(parent);
t.commit();
OUTPUT : Code:
SQL> select * from parent1;
PARENT_ID_PARENT PARENTNAME
-------------------------------- -----------
8a8080e7fefc5b3100fefc5b528b0002 Parent
SQL> select * from child1;
CHILD_ID_CHILD CHILD_ID_PARENT CHILDNAME
-------------------------------- -------------------------------- ----------
8a8080e7fefc5b3100fefc5b3c670001 8a8080e7fefc5b3100fefc5b528b0002 Child
hibernate goes :
Hibernate: insert into Child1 (childName, child_id_child) values (?, ?)
Hibernate: insert into Parent1 (ParentName, parent_id_parent) values (?, ?)
Hibernate: update Child1 set CHILD_ID_PARENT=? where child_id_child=?
hope it works now.....(works for me....)....
Nir