* attach(d1) => FAIL
* tx.commit
*/
public void testVersion8() {
logger.log(BasicLevel.DEBUG, "***************testVersion8*****************");
Team t = new Team("T8",null,null);
Collection players = new ArrayList();
Player p1 = new Player("p15", t, 20);
players.add(p1);
Player p2 = new Player("p16", t, 30);
players.add(p2);
t.setPlayers(players);
Coach c = new Coach("c8", 10, t);
t.setCoach(c);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
pm.makePersistent(t);
pm.currentTransaction().commit();
//begin
pm.currentTransaction().begin();
//detach the team t
Team copyOfT1 = (Team) pm.detachCopy(t);
//detach the team t
Team copyOfT2 = (Team) pm.detachCopy(t);
//commit
pm.currentTransaction().commit();
//modify the copy1
copyOfT1.getCoach().setExperience(99);
Iterator it = copyOfT1.getPlayers().iterator();
//modify the players
while(it.hasNext()){
Player p = (Player) it.next();
p.setAge(99);
}
//modify the copy2
copyOfT2.getCoach().setExperience(99);
it = copyOfT2.getPlayers().iterator();
//modify the players
while(it.hasNext()){
Player p = (Player) it.next();
p.setAge(99);
}
boolean attach2OK = false;
try{
pm.currentTransaction().begin();
//attach the copy2
Team attachedTeam2 = (Team) pm.makePersistent(copyOfT2);
pm.currentTransaction().commit();
attach2OK = true;
pm.currentTransaction().begin();
//attach the copy1
Team attachedTeam1 = (Team) pm.makePersistent(copyOfT1);
pm.currentTransaction().commit();
fail("The attach of copy1 is supposed to fail");
}catch(Exception e){
assertTrue("The attach of copy2 is supposed to be ok.", attach2OK);
assertEquals("Wrong exception thrown: " + e.getClass(), JDOException.class, e.getClass());