[jira] Created: (JDO-392) Deletion of objects when foreign-key is present : unexpected DB exceptions now handled
Deletion of objects when foreign-key is present : unexpected DB exceptions now handled -- Key: JDO-392 URL: http://issues.apache.org/jira/browse/JDO-392 Project: JDO Type: Bug Components: tck20 Versions: JDO 2 final Reporter: Andy Jefferson When I change JPOX to check for foreign-key constraints and when deleting an object with a FK present to just leave it to the DB to decide what to do (based on the specified FK) the DB throws exceptions. Such as [java] 1) test(org.apache.jdo.tck.extents.CloseAll)javax.jdo.JDODataStoreException: Delete request failed: DELETE FROM datastoreidentity0.PERSONS WHERE DATASTORE_IDENTITY=? [java] at org.jpox.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:274) [java] at org.jpox.store.rdbms.table.ClassTable.delete(ClassTable.java:2495) [java] at org.jpox.store.StoreManager.delete(StoreManager.java:902) [java] at org.jpox.state.StateManagerImpl.internalDeletePersistent(StateManagerImpl.java:4206) [java] at org.jpox.state.StateManagerImpl.deletePersistent(StateManagerImpl.java:4161) [java] at org.jpox.AbstractPersistenceManager.internalDeletePersistent(AbstractPersistenceManager.java:1393) [java] at org.jpox.AbstractPersistenceManager.deletePersistent(AbstractPersistenceManager.java:1404) [java] at org.apache.jdo.tck.extents.ExtentTest.deleteEmployee(ExtentTest.java:200) [java] at org.apache.jdo.tck.extents.CloseAll.test(CloseAll.java:61) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [java] at org.apache.jdo.tck.JDO_Test.runBare(JDO_Test.java:237) [java] at org.apache.jdo.tck.util.BatchTestRunner.doRun(BatchTestRunner.java:107) [java] at org.apache.jdo.tck.util.BatchTestRunner.start(BatchTestRunner.java:147) [java] at org.apache.jdo.tck.util.BatchTestRunner.main(BatchTestRunner.java:122) [java] NestedThrowablesStackTrace: [java] ERROR 23503: DELETE on table 'PERSONS' caused a violation of foreign key constraint 'PERS_MANAGER_FK' for key (885). The statement has been rolled back. [java] at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) [java] at org.apache.derby.impl.sql.execute.ReferencedKeyRIChecker.doCheck(Unknown Source) [java] at org.apache.derby.impl.sql.execute.RISetChecker.doPKCheck(Unknown Source) [java] at org.apache.derby.impl.sql.execute.DeleteResultSet.runFkChecker(Unknown Source) [java] at org.apache.derby.impl.sql.execute.DeleteResultSet.open(Unknown Source) [java] at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedPreparedStatement.execute(Unknown Source) [java] at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:911) [java] at org.jpox.store.rdbms.ParamLoggingPreparedStatement.execute(ParamLoggingPreparedStatement.java:213) [java] at org.jpox.store.rdbms.request.Request.executeUpdate(Request.java:88) [java] at org.jpox.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:260) [java] at org.jpox.store.rdbms.table.ClassTable.delete(ClassTable.java:2495) [java] at org.jpox.store.StoreManager.delete(StoreManager.java:902) [java] at org.jpox.state.StateManagerImpl.internalDeletePersistent(StateManagerImpl.java:4206) [java] at org.jpox.state.StateManagerImpl.deletePersistent(StateManagerImpl.java:4161) [java] at org.jpox.AbstractPersistenceManager.internalDeletePersistent(AbstractPersistenceManager.java:1393) [java] at org.jpox.AbstractPersistenceManager.deletePersistent(AbstractPersistenceManager.java:1404) [java] at org.apache.jdo.tck.extents.ExtentTest.deleteEmployee(ExtentTest.java:200) [java] at org.apache.jdo.tck.extents.CloseAll.test(CloseAll.java:61) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [java] at org.apache.jdo.tck.JDO_Test.runBare(JDO_Test.java:237) The deletion of objects should be handled by the TCK or better defined. Alternatively the JDO2 spec should define
[jira] Updated: (JDO-392) Deletion of objects when foreign-key is present : unexpected DB exceptions not handled
[ http://issues.apache.org/jira/browse/JDO-392?page=all ] Andy Jefferson updated JDO-392: --- Summary: Deletion of objects when foreign-key is present : unexpected DB exceptions not handled (was: Deletion of objects when foreign-key is present : unexpected DB exceptions now handled) Deletion of objects when foreign-key is present : unexpected DB exceptions not handled -- Key: JDO-392 URL: http://issues.apache.org/jira/browse/JDO-392 Project: JDO Type: Bug Components: tck20 Versions: JDO 2 final Reporter: Andy Jefferson When I change JPOX to check for foreign-key constraints and when deleting an object with a FK present to just leave it to the DB to decide what to do (based on the specified FK) the DB throws exceptions. Such as [java] 1) test(org.apache.jdo.tck.extents.CloseAll)javax.jdo.JDODataStoreException: Delete request failed: DELETE FROM datastoreidentity0.PERSONS WHERE DATASTORE_IDENTITY=? [java] at org.jpox.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:274) [java] at org.jpox.store.rdbms.table.ClassTable.delete(ClassTable.java:2495) [java] at org.jpox.store.StoreManager.delete(StoreManager.java:902) [java] at org.jpox.state.StateManagerImpl.internalDeletePersistent(StateManagerImpl.java:4206) [java] at org.jpox.state.StateManagerImpl.deletePersistent(StateManagerImpl.java:4161) [java] at org.jpox.AbstractPersistenceManager.internalDeletePersistent(AbstractPersistenceManager.java:1393) [java] at org.jpox.AbstractPersistenceManager.deletePersistent(AbstractPersistenceManager.java:1404) [java] at org.apache.jdo.tck.extents.ExtentTest.deleteEmployee(ExtentTest.java:200) [java] at org.apache.jdo.tck.extents.CloseAll.test(CloseAll.java:61) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [java] at org.apache.jdo.tck.JDO_Test.runBare(JDO_Test.java:237) [java] at org.apache.jdo.tck.util.BatchTestRunner.doRun(BatchTestRunner.java:107) [java] at org.apache.jdo.tck.util.BatchTestRunner.start(BatchTestRunner.java:147) [java] at org.apache.jdo.tck.util.BatchTestRunner.main(BatchTestRunner.java:122) [java] NestedThrowablesStackTrace: [java] ERROR 23503: DELETE on table 'PERSONS' caused a violation of foreign key constraint 'PERS_MANAGER_FK' for key (885). The statement has been rolled back. [java] at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) [java] at org.apache.derby.impl.sql.execute.ReferencedKeyRIChecker.doCheck(Unknown Source) [java] at org.apache.derby.impl.sql.execute.RISetChecker.doPKCheck(Unknown Source) [java] at org.apache.derby.impl.sql.execute.DeleteResultSet.runFkChecker(Unknown Source) [java] at org.apache.derby.impl.sql.execute.DeleteResultSet.open(Unknown Source) [java] at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedPreparedStatement.execute(Unknown Source) [java] at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:911) [java] at org.jpox.store.rdbms.ParamLoggingPreparedStatement.execute(ParamLoggingPreparedStatement.java:213) [java] at org.jpox.store.rdbms.request.Request.executeUpdate(Request.java:88) [java] at org.jpox.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:260) [java] at org.jpox.store.rdbms.table.ClassTable.delete(ClassTable.java:2495) [java] at org.jpox.store.StoreManager.delete(StoreManager.java:902) [java] at org.jpox.state.StateManagerImpl.internalDeletePersistent(StateManagerImpl.java:4206) [java] at org.jpox.state.StateManagerImpl.deletePersistent(StateManagerImpl.java:4161) [java] at org.jpox.AbstractPersistenceManager.internalDeletePersistent(AbstractPersistenceManager.java:1393) [java] at org.jpox.AbstractPersistenceManager.deletePersistent(AbstractPersistenceManager.java:1404) [java] at org.apache.jdo.tck.extents.ExtentTest.deleteEmployee(ExtentTest.java:200) [java] at org.apache.jdo.tck.extents.CloseAll.test(CloseAll.java:61) [java] at
[jira] Commented: (JDO-392) Deletion of objects when foreign-key is present : unexpected DB exceptions not handled
[ http://issues.apache.org/jira/browse/JDO-392?page=comments#action_12420394 ] Craig Russell commented on JDO-392: --- JDO assumes that during a transaction, the persistent instances in memory might be out of sync with the persistent instances in the datastore. The application does not need to be written so as to guarantee consistency with each individual memory operation. The spec is pretty specific about when instances are removed from the datastore: spec 12.6.7 These methods delete persistent instances from the datastore. They must be called in the context of an active transaction, or a JDOUserException is thrown. The representation in the datastore will be deleted when this instance is flushed to the datastore (via commit or evict). ... If deleting an instance would violate datastore integrity constraints, it is implementation- defined whether an exception is thrown at commit time, or the delete operation is simply ignored. Portable applications should use this method to delete instances from the datas- tore, and not depend on any reachability algorithm to automatically delete instances. /spec 12.6.7 I think that both of the above paragraphs need some expert group discussion. I'll raise this on the expert group alias. Deletion of objects when foreign-key is present : unexpected DB exceptions not handled -- Key: JDO-392 URL: http://issues.apache.org/jira/browse/JDO-392 Project: JDO Type: Bug Components: tck20 Versions: JDO 2 final Reporter: Andy Jefferson When I change JPOX to check for foreign-key constraints and when deleting an object with a FK present to just leave it to the DB to decide what to do (based on the specified FK) the DB throws exceptions. Such as [java] 1) test(org.apache.jdo.tck.extents.CloseAll)javax.jdo.JDODataStoreException: Delete request failed: DELETE FROM datastoreidentity0.PERSONS WHERE DATASTORE_IDENTITY=? [java] at org.jpox.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:274) [java] at org.jpox.store.rdbms.table.ClassTable.delete(ClassTable.java:2495) [java] at org.jpox.store.StoreManager.delete(StoreManager.java:902) [java] at org.jpox.state.StateManagerImpl.internalDeletePersistent(StateManagerImpl.java:4206) [java] at org.jpox.state.StateManagerImpl.deletePersistent(StateManagerImpl.java:4161) [java] at org.jpox.AbstractPersistenceManager.internalDeletePersistent(AbstractPersistenceManager.java:1393) [java] at org.jpox.AbstractPersistenceManager.deletePersistent(AbstractPersistenceManager.java:1404) [java] at org.apache.jdo.tck.extents.ExtentTest.deleteEmployee(ExtentTest.java:200) [java] at org.apache.jdo.tck.extents.CloseAll.test(CloseAll.java:61) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [java] at org.apache.jdo.tck.JDO_Test.runBare(JDO_Test.java:237) [java] at org.apache.jdo.tck.util.BatchTestRunner.doRun(BatchTestRunner.java:107) [java] at org.apache.jdo.tck.util.BatchTestRunner.start(BatchTestRunner.java:147) [java] at org.apache.jdo.tck.util.BatchTestRunner.main(BatchTestRunner.java:122) [java] NestedThrowablesStackTrace: [java] ERROR 23503: DELETE on table 'PERSONS' caused a violation of foreign key constraint 'PERS_MANAGER_FK' for key (885). The statement has been rolled back. [java] at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) [java] at org.apache.derby.impl.sql.execute.ReferencedKeyRIChecker.doCheck(Unknown Source) [java] at org.apache.derby.impl.sql.execute.RISetChecker.doPKCheck(Unknown Source) [java] at org.apache.derby.impl.sql.execute.DeleteResultSet.runFkChecker(Unknown Source) [java] at org.apache.derby.impl.sql.execute.DeleteResultSet.open(Unknown Source) [java] at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source) [java] at org.apache.derby.impl.jdbc.EmbedPreparedStatement.execute(Unknown Source) [java] at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:911) [java] at org.jpox.store.rdbms.ParamLoggingPreparedStatement.execute(ParamLoggingPreparedStatement.java:213) [java] at
Behavior of deletePersistent with datastore constraints
Javadogs,JDO assumes that during a transaction, the persistent instances in memory might be out of sync with the persistent instances in the datastore. The application does not need to be written so as to guarantee consistency with each individual memory operation. The spec is pretty specific about when instances are removed from the datastore: spec 12.6.7 These methods delete persistent instances from the datastore. They must be called in the context of an active transaction, or a JDOUserException is thrown. The representation in the datastore will be deleted when this instance is flushed to the datastore (via commit or evict). ... If deleting an instance would violate datastore integrity constraints, it is implementation- defined whether an exception is thrown at commit time, or the delete operation is simply ignored. Portable applications should use this method to delete instances from the datas- tore, and not depend on any reachability algorithm to automatically delete instances. /spec 12.6.7 I'd like to discuss the two items above. The spec requires that deletes be deferred until flush, but I suspect that this overconstrains the possible implementations. I would leave it up to the implementation to decide whether to delete immediately or defer until flush. But if it deletes the instance immediately, it would also have to nullify any foreign keys that refer to it in order to avoid an immediate constraint violation. And I don't believe that this should be done automatically unless the user specifically asked for it, via a metadata annotation on the foreign key delete-action="" If the implementation wanted to nullify the referring key where the constraint was defined as anything else, it would have to guarantee at flush time that the user had set the field to null or something else, or all the referring objects themselves were deleted.With regard to integrity constraints, the second paragraph leaves me cold. I don't know what I was thinking when I wrote "or the delete operation is simply ignored". When would ignoring a delete from the application ever be the right behavior?Comments? Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:[EMAIL PROTECTED] P.S. A good JDO? O, Gasp! smime.p7s Description: S/MIME cryptographic signature