Entity e = Book.newBookEntity("harold", "1234", "the title");
ds.put(e);
Book b = em.find(Book.class, e.getKey());
// make a copy right away, otherwise our change will get reverted when the txn rolls back
ExceptionThrowingDatastoreDelegate dd =
new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
setDelegateForThread(dd);
try {
// update attached object
try {
b.setFirstPublished(1988);
em.merge(b);
em.close();
fail("expected exception");
} catch (PersistenceException ex) {
assertTrue(ex.getCause() instanceof ConcurrentModificationException);
} catch (NucleusDataStoreException nde) {
assertTrue(nde.getCause() instanceof ConcurrentModificationException);
}
em = emf.createEntityManager();
b = em.find(Book.class, e.getKey());
// update attached object
b.setFirstPublished(1988);
em.merge(b);
em.close();
em = emf.createEntityManager();
b = em.find(Book.class, e.getKey());
assertEquals(b, "harold", "1234", 1988, "the title");
em.close();
} finally {
setDelegateForThread(dd.getInner());
}
}