This is my problem:
I have a Parent table and a child table. I have Set object in my master table DTO class as to refer the my child table.
E.g
public class Parent {
Set childrent;
...
...
}
This is my parent table hibernate mapping file
<hibernate-mapping >
<class name="Parent" table="PARENT">
<id name="id" type="long" unsaved-value="0">
<column name="ID"/>
<generator class="native">
<param name="sequence">SEQ_ID</param>
</generator>
</id>
<set name="children" table="CHILD" lazy="true" cascade="all">
<key column="Parent_ID"/>
<one-to-many class="Child"/>
</set>
</class>
</hibernate-mapping>
This is my child table hibernate mapping file
<hibernate-mapping >
<class name="Child" table="CHILD">
<id name="childId" type="long" unsaved-value="0">
<column name="CHILD_ID"/>
<generator class="native">
<param name="sequence">SEQ_CHILD_ID</param>
</generator>
</id>
<property name="id" type="long">
<column name="ID" />
</property >
</class>
</hibernate-mapping>
I have made constraint that the ID column in the Child table is referenced by foriegn key ID of Parent table.
When I try to save Parent object through session, I am getting following exception.
org.springframework.dao.DataIntegrityViolationException:
Hibernate operation:Could not execute JDBC batch update;
SQL
[insert
into
CHILD
(CHILD_ID,
ID)
values
(?,
?];
ORA-02291:
integrity
constraint
(TEST.CHILD_FK1)
violated
-
parent
key
not
found ;
nested
exception
is
java.sql.BatchUpdateException:
ORA-02291:
integrity
constraint
(TEST.CHILD_FK1)
violated
-
parent
key
not
found at
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:235) at
org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424) at
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:411) at
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:363) at
org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:595) at
com.openreach.portal.serviceaccess
Am I missing some thing?
I am using Oracle10g as DB and application server is Weblogic 8.1.
Appriciate your help.
Thanks & Regards,
Siraj
|