2 Replies Latest reply on Feb 24, 2005 7:59 PM by Ian Ian

    Bug in deletion with 2nd CMR when first is a batch-cascade-d

    Ian Ian Newbie

      I believe I've discovered a bug with deleting of entites when the deleted entity has 2 CMR's - one requiring the batch-cascade-delete option but the other not occuring (the problem is with the non-cascade-delete option). I'm running version 4.0.1.

      I have 3 beans (A, B, and C). A has a 1-1 mandatory relationship with B, with B having a non-nullable foreign key in A. A has a 1-many relationship with C, and C is marked for cascade-delete. The problem occurs when you populate A (which means B must be populated), and C is populated with references to A. Then you delete A.

      From the trace, you can see that the batch-cascade-delete work is deferred on relationship C. Then it attempts to set the foreign key field of B to null in A - which is not allowed, and a database constraint is activated.

      If you remove the relationship from A to C, everything is fine. If you don't populate C, everything is fine.

      I have included two portions of traces from the log files. If I could attach a copy of the project, I would do so (it's a simple project generated simply to demonstrate this problem).

      This portion of the log file occurs when C is populated (deleting A):

      2005-02-25 09:53:10,772 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.A] RESET PERSISTENCE CONTEXT: id=[.1.]
      2005-02-25 09:53:10,772 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] load data: entity=A pk=[.1.]
      2005-02-25 09:53:10,772 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] No preload data found: entity=A pk=[.1.]
      2005-02-25 09:53:10,772 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.A] Default eager-load for entity: readahead=null
      2005-02-25 09:53:10,772 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.A] Executing SQL: SELECT fk_B FROM A_TABLE WHERE (pk_A=?)
      2005-02-25 09:53:10,772 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.A#pkA] param: i=1, type=INTEGER, value=1
      2005-02-25 09:53:10,772 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.A#fkB] result: i=1, type=java.lang.Integer, value=1000
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.A.c] Read ahead cahce load: cmrField=c pk=[.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] load data: entity=A pk=[.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] No preload data found: entity=A pk=[.1.]
      2005-02-25 09:53:10,782 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.A] load relation SQL: SELECT pk_C FROM C_TABLE WHERE (fk_A=?)
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.C#pkA] param: i=1, type=INTEGER, value=1
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.C#pkC] result: i=1, type=java.lang.Integer, value=1
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.C] Add preload data: entity=C pk=[.1.] field=a
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.C#pkC] result: i=1, type=java.lang.Integer, value=2
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.C] Add preload data: entity=C pk=[.2.] field=a
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.C] Add finder results: entity=C results=[[.1.], [.2.]] readahead=[JDBCReadAheadMetaData : strategy=on-load, pageSize=1000, eagerLoadGroup=*, left-join[]]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.C] RESET PERSISTENCE CONTEXT: id=[.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.C] load data: entity=C pk=[.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.C] Preloading data: entity=C pk=[.1.] cmrField=a
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.C] Scheduled for batch-cascade-delete: [.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.C] RESET PERSISTENCE CONTEXT: id=[.2.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.C] load data: entity=C pk=[.2.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.C] Preloading data: entity=C pk=[.2.] cmrField=a
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.C] Scheduled for batch-cascade-delete: [.2.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.A.b] Read ahead cahce load: cmrField=b pk=[.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] load data: entity=A pk=[.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] No preload data found: entity=A pk=[.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.B] RESET PERSISTENCE CONTEXT: id=[.1000.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.B] load data: entity=B pk=[.1000.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.B] No preload data found: entity=B pk=[.1000.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.B] Default eager-load for entity: readahead=null
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.B] Remove relation: field=A_b id=[.1000.] relatedId=[.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.CascadeDeleteStrategy$BatchCascadeDeleteStrategy.A] Removing [.1.]
      2005-02-25 09:53:10,782 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.A] Remove relation: field=c id=[.1.] relatedId=[.1.]
      2005-02-25 09:53:10,792 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.A] Executing SQL: UPDATE A_TABLE SET fk_B=? WHERE pk_A=?
      2005-02-25 09:53:10,792 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.A#fkB] param: i=1, type=INTEGER, value=NULL
      2005-02-25 09:53:10,792 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.A#pkA] param: i=2, type=INTEGER, value=1
      2005-02-25 09:53:10,802 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException in method: public abstract void javax.ejb.EJBLocalObject.remove() throws javax.ejb.RemoveException,javax.ejb.EJBException, causedBy:
      java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'fk_B', table 'Dev.dbo.A_TABLE'; column does not allow nulls. UPDATE fails.


      This is the log when table C is not populated and A is deleted (and everything works):
      2005-02-25 09:56:13,309 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.A] RESET PERSISTENCE CONTEXT: id=[.1.]
      2005-02-25 09:56:13,309 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] load data: entity=A pk=[.1.]
      2005-02-25 09:56:13,309 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] No preload data found: entity=A pk=[.1.]
      2005-02-25 09:56:13,309 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.A] Default eager-load for entity: readahead=null
      2005-02-25 09:56:13,309 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.A] Executing SQL: SELECT fk_B FROM A_TABLE WHERE (pk_A=?)
      2005-02-25 09:56:13,309 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.A#pkA] param: i=1, type=INTEGER, value=1
      2005-02-25 09:56:13,309 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.A#fkB] result: i=1, type=java.lang.Integer, value=1000
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.A.c] Read ahead cahce load: cmrField=c pk=[.1.]
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] load data: entity=A pk=[.1.]
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] No preload data found: entity=A pk=[.1.]
      2005-02-25 09:56:13,319 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.A] load relation SQL: SELECT pk_C FROM C_TABLE WHERE (fk_A=?)
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.C#pkA] param: i=1, type=INTEGER, value=1
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.A.b] Read ahead cahce load: cmrField=b pk=[.1.]
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] load data: entity=A pk=[.1.]
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] No preload data found: entity=A pk=[.1.]
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.B] RESET PERSISTENCE CONTEXT: id=[.1000.]
      2005-02-25 09:56:13,319 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.B] load data: entity=B pk=[.1000.]
      2005-02-25 09:56:13,329 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.B] No preload data found: entity=B pk=[.1000.]
      2005-02-25 09:56:13,329 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.B] Default eager-load for entity: readahead=null
      2005-02-25 09:56:13,329 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.B] Remove relation: field=A_b id=[.1000.] relatedId=[.1.]
      2005-02-25 09:56:13,329 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.A] Executing SQL: DELETE FROM A_TABLE WHERE pk_A=?
      2005-02-25 09:56:13,329 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.A#pkA] param: i=1, type=INTEGER, value=1
      2005-02-25 09:56:13,329 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.A] Remove: Rows affected = 1
      2005-02-25 09:56:13,329 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.A] Removing cached data for [.1.]