hi
I am new to hibernate and trying to implement a small example with parent -child relationship(one to many).I did set up the one to many relationship in the config files and tried to perform insert and delete operations.insert works fine it inserts child record on calling insert on parent but the delete doesn't work.When i call delete on parent it gives me the constraint violation error.Can somebody tell me what am i doing wrong.Here are the sample config files and sample code for deletion.
child.hbm.xml
Code:
<many-to-one name="Parent" column="parent_id" class="Parent" not-null="true">
</many-to-one>
parent.hbm.xml
Code:
<set name="Children" inverse="true" cascade="all-delete-orphan" >
<key column="parent_id"/>
<one-to-many class="Child" />
</set>
delete function code:
Code:
try
{
SessionFactory sessionFactory = new Configuration()
.configure().buildSessionFactory();
Session session = sessionFactory.openSession();
tx = session.beginTransaction();
parent.getChildren().remove(child);
session.delete(parent);
tx.commit();
System.out.println("Delete Successful!");
}
this is the error i get when i delete parent
Quote:
Caused by: java.sql.BatchUpdateException: ORA-02292: integrity constraint violated - child record found
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:342)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10768)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 9 more