Buggy code:
public class TestDependentFields2 extends BaseKernelTest { private static final int COMMIT = 0 ; private static final int ROLLBACK = 1 ; private static final int PRESTORE = 2 ; private Object _root = null ; private Object _rel = null ; private Object _depRel = null ; private Object _deep = null ; private Object _coll = null ; private Object _depColl = null ; private Object _map = null ; private Object _depMap = null ; private Object _repeat = null ; public TestDependentFields2 ( String casename ) { } public void setUp ( ) throws Exception { } public void testDependentFieldsLoaded ( ) { } public void testDependentFieldsLoadedWithRollback ( ) { } public void testDependentFieldsLoadedWithPreStore ( ) { } public void testDependentFieldsUnloaded ( ) { } public void testDependentFieldsUnloadedWithRollback ( ) { } public void testDependentFieldsUnloadedWithPreStore ( ) { } private void delete ( boolean load , int action ) { } private void checkFields ( ) { } public void testNullDeletesDependent ( ) { } public void testNullDeletesDependentWithRollback ( ) { } public void testNullDeletesDependentWithPreStore ( ) { } private void nullDeletesDependent ( int action ) { } public void testRemoveDeletesDependent ( ) { } public void testRemoveDeletesDependentWithRollback ( ) { } public void testRemoveDeletesDependentWithPreStore ( ) { } private void removeDeletesDependent ( int action ) { } public void testMoveDependentInContainer ( ) { } public void testMoveDependentInContainerWithRollback ( ) { } public void testMoveDependentInContainerWithPreStore ( ) { } private void moveDependentInContainer ( int action ) { } public void testRefedDependentNotDeleted ( ) { } public void testRefedDependentNotDeletedWithRollback ( ) { } public void testRefedDependentNotDeletedWithPreStore ( ) { } private void refedDependentNotDeleted ( int action ) { } public void testNullSharedDependent ( ) { } public void testNullSharedDependentWithRollback ( ) { } public void testNullSharedDependentWithPreStore ( ) { } private void nullSharedDependent ( int action ) { } public void testClearMappedDependentOfDetached ( ) { } public void testClearInverseKeyDependentOfDetached ( ) { } private void clearDependentOfDetachedTest ( boolean mapped ) { deleteAll ( DependentFieldsPC . class ) ; DependentFieldsPC owner = new DependentFieldsPC ( ) ; for ( int i = 0 ; i < 2 ; i ++ ) { DependentFieldsPC child = new DependentFieldsPC ( ) ; if ( mapped ) { owner . getDependentMappedList ( ) . add ( child ) ; child . setOwner ( owner ) ; } else owner . getDependentInverseKeyList ( ) . add ( child ) ; } OpenJPAEntityManager pm = ( ( OpenJPAEntityManager ) ( currentEntityManager ( ) ) ) ; startTx ( pm ) ; pm . persist ( owner ) ; endTx ( pm ) ; Object oid = pm . getObjectId ( owner ) ; assertEquals ( 3 , ( ( org . apache . openjpa . persistence . Extent ) ( pm . createExtent ( DependentFieldsPC . class , true ) ) ) . list ( ) . size ( ) ) ; endEm ( pm ) ; pm = ( ( OpenJPAEntityManager ) ( currentEntityManager ( ) ) ) ; owner = ( ( DependentFieldsPC ) ( pm . find ( DependentFieldsPC . class , oid ) ) ) ; if ( mapped ) assertEquals ( 2 , owner . getDependentMappedList ( ) . size ( ) ) ; else assertEquals ( 2 , owner . getDependentInverseKeyList ( ) . size ( ) ) ; <START_BUG> DependentFieldsPC detached = ( ( DependentFieldsPC ) ( pm . detach ( owner ) ) ) ; <END_BUG> endEm ( pm ) ; if ( mapped ) { assertEquals ( 2 , detached . getDependentMappedList ( ) . size ( ) ) ; detached . getDependentMappedList ( ) . clear ( ) ; } else { assertEquals ( 2 , detached . getDependentInverseKeyList ( ) . size ( ) ) ; detached . getDependentInverseKeyList ( ) . clear ( ) ; } pm = ( ( OpenJPAEntityManager ) ( currentEntityManager ( ) ) ) ; startTx ( pm ) ; owner = ( ( DependentFieldsPC ) ( pm . merge ( detached ) ) ) ; if ( mapped ) assertEquals ( 0 , owner . getDependentMappedList ( ) . size ( ) ) ; else assertEquals ( 0 , owner . getDependentInverseKeyList ( ) . size ( ) ) ; endTx ( pm ) ; assertEquals ( 1 , ( ( org . apache . openjpa . persistence . Extent ) ( pm . createExtent ( DependentFieldsPC . class , true ) ) ) . list ( ) . size ( ) ) ; endEm ( pm ) ; pm = ( ( OpenJPAEntityManager ) ( currentEntityManager ( ) ) ) ; owner = ( ( DependentFieldsPC ) ( pm . find ( DependentFieldsPC . class , oid ) ) ) ; if ( mapped ) assertEquals ( 0 , owner . getDependentMappedList ( ) . size ( ) ) ; else assertEquals ( 0 , owner . getDependentInverseKeyList ( ) . size ( ) ) ; endEm ( pm ) ; } }

Fix:
DependentFieldsPC detached = ( ( DependentFieldsPC ) ( pm . detachCopy ( owner ) ) ) ;