ds.put(e);
beginTxn();
Book book = em.find(Book.class, e.getKey());
commitTxn();
CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
setDelegateForThread(dd);
try {
try {
// update detached object TODO The object here is not "detached" at all. It is HOLLOW
book.setFirstPublished(1988);
beginTxn();
// reattach
em.merge(book);
commitTxn();
fail("expected exception");
} catch (RollbackException ex) {
// good
assertTrue(ex.getCause() instanceof PersistenceException);
assertTrue(ex.getCause().getCause() instanceof ConcurrentModificationException);
} catch (NucleusDataStoreException nde) {
assertTrue(nde.getCause() instanceof ConcurrentModificationException);
}
assertFalse(em.getTransaction().isActive());
// now verify that the new value is still in the detached version.
assertEquals(book, "harold", "1234", 1988, "the title");
} finally {
setDelegateForThread(dd.getInner());
}
}