*/
public void testAttachNewObjectInCollection() {
logger.log(BasicLevel.DEBUG, "***************testAttachNewObjectInCollection*****************");
Team t = new Team("Le Mans",null,null);
Collection players = new ArrayList();
Player p1 = new Player("p11", t, 20);
players.add(p1);
Player p2 = new Player("p12", t, 30);
players.add(p2);
t.setPlayers(players);
Coach c = new Coach("c6", 10, t);
t.setCoach(c);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
logger.log(BasicLevel.DEBUG, "Make the team persistent " + t.toString());
pm.makePersistent(t);
pm.currentTransaction().commit();
try {
//detach the team
Team copyOfT = (Team) pm.detachCopy(t);
t = null;
//create a new player
String newPlayerName = "pXX";
Player newPlayer = new Player(newPlayerName, copyOfT, 35);
copyOfT.addPlayer(newPlayer);
//attach the team
pm.currentTransaction().begin();
Team attachedTeam = (Team) pm.makePersistent(copyOfT);
pm.currentTransaction().commit();
Iterator it = attachedTeam.getPlayers().iterator();
boolean newPlayerFound = false;
while(!newPlayerFound && it.hasNext()) {
Player p = (Player) it.next();
if (p.getName().equals(newPlayerName)) {
assertTrue("The new player is not a persistent object", ((JDOPersistentObjectItf) p).jdoIsPersistent());
newPlayerFound = true;
}
}
assertTrue("The new player should have been made persistent", newPlayerFound);