public void cascadeAllMXMTest4() throws Exception {
    logTrace( "Begin cascadeAllMXMTest4");
    boolean pass = false;
    A a1;
    Collection newCol;
    try {
       final B b1 = new B("1", "b1", 5);
       final B b2 = new B("2", "b2", 5);
       final B b3 = new B("3", "b3", 5);
       final B b4 = new B("4", "b4", 5);
       Vector v1 = new Vector();
       v1.add(b1);
       v1.add(b2);
       v1.add(b3);
       v1.add(b4);
       getEntityTransaction().begin();
       logTrace( "New A instance");
       a1 = new A("5", "bean5", 5, v1);
       getEntityManager().persist(a1);
       newCol = a1.getBCol();
       dumpCollectionDataB(newCol);
       if (newCol.contains(b1) && newCol.contains(b2) && newCol.contains(b3) && newCol.contains(b4)) {
          try {
             logTrace( "Remove instances");
             getEntityManager().remove(findB("1"));
             getEntityManager().remove(findB("2"));
             getEntityManager().remove(findB("3"));
             getEntityManager().remove(findB("4"));
             getEntityManager().remove(a1);
             if ((!getEntityManager().contains(a1))) {
                pass = true;
             }
             getEntityTransaction().commit();
          } catch (Exception fe) {
             logErr( "Unexpected exception caught trying to remove entity instance :",
                   fe);
          }
       } else {
          logErr( "Test failed");
          pass = false;
       }
    } catch (Exception e) {
       logErr( "Unexpected exception occurred", e);
    }
    if (!pass) {
       throw new Exception("cascadeAllMXMTest4 failed");
    }
}
[4] java.lang.IllegalArgumentException: Entity must be managed to call remove: ee.jakarta.tck.persistence.core.entitytest.cascadeall.manyXmany.B@3e7a7f36, try merging the detached and try the remove again.