* tx.commit
* attach => FAIL
*/
public void testVersion3() {
logger.log(BasicLevel.DEBUG, "***************testVersion3*****************");
Team t = new Team("T3",null,null);
Collection players = new ArrayList();
Player p1 = new Player("p5", t, 20);
players.add(p1);
Player p2 = new Player("p6", t, 30);
players.add(p2);
t.setPlayers(players);
Coach c = new Coach("c3", 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 copyOfT = null;
try {
copyOfT = (Team) pm.detachCopy(t);
// modify the coach
t.setCoach(new Coach("c31", 10, t));
Iterator it = t.getPlayers().iterator();
//modify the players
while(it.hasNext()){
Player p = (Player) it.next();
p.setAge(99);
}
//commit
pm.currentTransaction().commit();
} catch (Exception e) {
fail("Detach error: " + e.getMessage());
pm.currentTransaction().rollback();
pm.close();
return;
}
pm.currentTransaction().begin();
try{
//attach the team
Team attachedTeam = (Team) pm.makePersistent(copyOfT);
pm.currentTransaction().commit();
fail("The attached is supposed to fail");
}catch(Exception e){
assertEquals("Wrong exception thrown: " + e.getClass(), JDOException.class, e.getClass());
} finally {