Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Hibernate Help .ORA-02292: integrity constraint violated child record found

807580Mar 30 2010 — edited Apr 12 2010
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.I want to delete the child record too when delete on parent is called.Can somebody tell me what am i doing wrong.Here are the sample config files and sample code for deletion.
child.hbm.xml
<many-to-one name="Parent" column="parent_id" class="Parent" not-null="true">
</many-to-one>
parent.hbm.xml:
<set name="Children" inverse="true"  cascade="all-delete-orphan" >
          <key column="parent_id"/>
          <one-to-many class="Child" />
      </set>
delete function 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!");
    }
Exception raised:
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2010
Added on Mar 30 2010
6 comments
3,821 views