};
Entity e = Book.newBookEntity("harold", "1234", "the title");
ds.put(e);
beginTxn();
Book b = em.find(Book.class, e.getKey());
ExceptionThrowingDatastoreDelegate dd =
new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
setDelegateForThread(dd);
try {
try {
// update attached object TODO The object here is not "detached" at all. It is HOLLOW
b.setFirstPublished(1988);
commitTxn();
fail("expected exception");
} catch (RollbackException ex) {
// good
assertTrue(ex.getCause() instanceof PersistenceException);
assertTrue(ex.getCause().getCause() instanceof ConcurrentModificationException);
}
// rollback of txn causes state of pojo to rollback as well
assertEquals(2000, b.getFirstPublished());
assertFalse(em.getTransaction().isActive());
beginTxn();
// reapply the change
b.setFirstPublished(1988);
em.merge(b);
commitTxn();
beginTxn();
b = em.find(Book.class, e.getKey());
assertEquals(b, "harold", "1234", 1988, "the title");