pm.currentTransaction().begin();
C c = new C(1);
ArrayList ds = new ArrayList(MAP_SIZE * 2);
for(int i=0; i<MAP_SIZE; i++) {
String f1 = F1_PREFIX + i;
ds.add(new D(i, f1));
}
pm.makePersistent(c);
pm.makePersistentAll(ds);
pm.currentTransaction().commit();
//Add into the map
pm.currentTransaction().begin();
Map m = c.getDkey2d();
for(int i=0; i<MAP_SIZE; i++) {
D d = (D) ds.get(i);
m.put(d.getF1(), d);
}
pm.currentTransaction().commit();
pm.getFetchPlan().addGroup("all").removeGroup("default");
C copyOfC = (C) pm.detachCopy(c);
assertEquals("Not the same id for c and its detached copy", c.getMyid(), copyOfC.getMyid());
Map mC = c.getDkey2d();
Map mCopyOfC = copyOfC.getDkey2d();
assertEquals("The maps' size should be the same.",mC.size(), mCopyOfC.size());
Iterator itC = mC.values().iterator();
Collection col = mCopyOfC.values();
while(itC.hasNext()) {
D dC = (D) itC.next();
boolean contained = false;
Iterator it = col.iterator();
while (it.hasNext() && !contained) {
D dCopy = (D) it.next();
if (dC.getMyid()==dCopy.getMyid() && dC.getF1().equals(dCopy.getF1()))
contained = true;
}
assertTrue("The element " + dC.getMyid() + " is not contained", contained);
}
}