I know this has come up many many times in the past, but after looking through many archives in this forum, I still did not find a solution to my problem.
I am trying to delete an object which is the parent of a child. I have my cascade set to all-delete-orphan. Whenever I execute session.delete(object), I get a foreign key constraint violation thrown at me by oracle. The interesting thing is that it looks like the sequence of sql queries that hibernate is executing is correct. It first tries to delete the many end of the association (the childs) and the it issues the delete for the object on the single end of the relation. So I have no idea why I still get th FK errors. Could it be that in this instance Hibernate is not committing in the proper sequence in the database. All pertinent files are below.
Any help is appreciated.
Thanks,
Juan
Hibernate version:2.16
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping> <class name="com.uaig.migration.oracle10g.vo.OracleVehicleMake" table="VEHICLE_MAKE" dynamic-update="false" dynamic-insert="false" >
<id name="makeId" column="make_id" type="integer" > <generator class="sequence"> <param name="sequence">vehiclemake_seq</param> </generator> </id>
<set name="models" table="VEHICLE_MODEL" lazy="true" inverse="true" cascade="all-delete-orphan" sort="unsorted" >
<key column="MAKE_ID" />
<one-to-many class="com.uaig.migration.oracle10g.vo.OracleVehicleModel" /> </set>
<property name="make" type="java.lang.String" update="true" insert="true" column="make" />
<!-- To add non XDoclet property mappings, create a file named hibernate-properties-OracleVehicleMake.xml containing the additional properties and place it in your merge dir. -->
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping> <class name="com.uaig.migration.oracle10g.vo.OracleVehicleModel" table="VEHICLE_MODEL" dynamic-update="false" dynamic-insert="false" >
<id name="modelId" column="MODEL_ID" type="java.lang.Integer" > <generator class="sequence"> <param name="sequence">vehiclemodel_seq</param> </generator> </id>
<property name="description" type="java.lang.String" update="true" insert="true" column="description" />
<many-to-one name="make" class="com.uaig.migration.oracle10g.vo.OracleVehicleMake" cascade="none" outer-join="auto" update="true" insert="true" column="MAKE_ID" />
<property name="model" type="java.lang.String" update="true" insert="true" column="model" />
<property name="prod" type="java.lang.String" update="true" insert="true" column="prod" />
<!-- To add non XDoclet property mappings, create a file named hibernate-properties-OracleVehicleModel.xml containing the additional properties and place it in your merge dir. -->
</class>
</hibernate-mapping>
Session session = HibernateUtil.currentOracleSession(); tx = session.beginTransaction(); Query q = session.createQuery("from OracleVehicleMake as make where make.make = :make"); q.setString("make", make); OracleVehicleMake veh = (OracleVehicleMake) q.list().get(0); Collection models = veh.getModels(); models.clear(); session.delete(veh); //log.debug("There were " + rowsDeleted + " deleted"); tx.commit(); log.debug("Deleted VehicleMake " + make); HibernateUtil.closeSession();
ERROR [main] (JDBCExceptionReporter.java:46) - ORA-02292: integrity constraint (SYSMAN.SYS_C0010950) violated - child record found
ERROR [main] (JDBCExceptionReporter.java:46) - ORA-02292: integrity constraint (SYSMAN.SYS_C0010950) violated - child record found
ERROR [main] (JDBCExceptionReporter.java:46) - ORA-02292: integrity constraint (SYSMAN.SYS_C0010950) violated - child record found
ERROR [main] (JDBCExceptionReporter.java:46) - ORA-02292: integrity constraint (SYSMAN.SYS_C0010950) violated - child record found
ERROR [main] (JDBCException.java:38) - Could not execute JDBC batch update java.sql.BatchUpdateException: ORA-02292: integrity constraint (SYSMAN.SYS_C0010950) violated - child record found
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8738) at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260) at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54) at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2376) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61) at com.uaig.migration.core.BaseMigration.deleteVehicleMakeByMake(BaseMigration.java:58) at com.uaig.migration.core.TestZipMigration.testDeleteVehicleMake(TestZipMigration.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) ERROR [main] (SessionImpl.java:2379) - Could not synchronize database state with session net.sf.hibernate.JDBCException: Could not execute JDBC batch update at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:133) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2376) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61) at com.uaig.migration.core.BaseMigration.deleteVehicleMakeByMake(BaseMigration.java:58) at com.uaig.migration.core.TestZipMigration.testDeleteVehicleMake(TestZipMigration.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) Caused by: java.sql.BatchUpdateException: ORA-02292: integrity constraint (SYSMAN.SYS_C0010950) violated - child record found
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8738) at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260) at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54) at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126) ... 19 more ERROR [main] (BaseMigration.java:104) - Caught a HibernateException...Please consult stacktrace: net.sf.hibernate.JDBCException: Could not execute JDBC batch update at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:133) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2376) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61) at com.uaig.migration.core.BaseMigration.deleteVehicleMakeByMake(BaseMigration.java:58) at com.uaig.migration.core.TestZipMigration.testDeleteVehicleMake(TestZipMigration.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) Caused by: java.sql.BatchUpdateException: ORA-02292: integrity constraint (SYSMAN.SYS_C0010950) violated - child record found
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8738) at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260) at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54) at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126) ... 19 more
Oracle 10g
|