use of org.datanucleus.samples.annotations.datastoreidentity.DSIDHolder in project tests by datanucleus.
the class DatastoreIdentityTest method testBasic.
/**
* Basic test.
*/
public void testBasic() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
Object id = null;
try {
tx.begin();
DSIDHolder holder = new DSIDHolder("First Holder");
em.persist(holder);
em.flush();
id = NucleusJPAHelper.getObjectId(holder);
tx.commit();
} catch (Exception e) {
LOG.error(e);
e.printStackTrace();
fail(e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
emf.getCache().evictAll();
em = getEM();
tx = em.getTransaction();
try {
tx.begin();
Object key = IdentityUtils.getTargetKeyForDatastoreIdentity(id);
DSIDHolder holder = em.find(DSIDHolder.class, key);
assertNotNull(holder);
assertEquals("First Holder", holder.getName());
tx.commit();
} catch (Exception e) {
LOG.error(e);
e.printStackTrace();
fail(e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(DSIDHolder.class);
}
}
Aggregations