use of org.datanucleus.samples.annotations.array.Permission in project tests by datanucleus.
the class ArrayTest method testArrayOfPersistablesViaJoin.
public void testArrayOfPersistablesViaJoin() {
try {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
ArrayHolder h1 = new ArrayHolder(1);
Permission p1 = new Permission(101, "Admin");
Permission p2 = new Permission(102, "Developer");
Permission[] perms = new Permission[] { p1, p2 };
h1.setPermissions(perms);
em.persist(h1);
em.persist(p1);
em.persist(p2);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
emf.getCache().evictAll();
em = emf.createEntityManager();
tx = em.getTransaction();
try {
tx.begin();
ArrayHolder h1 = em.find(ArrayHolder.class, 1);
assertNotNull(h1);
Permission[] perms = h1.getPermissions();
assertNotNull(perms);
assertEquals(2, perms.length);
assertEquals(101, perms[0].getId());
assertEquals(102, perms[1].getId());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(ArrayHolder.class);
clean(Permission.class);
}
}
Aggregations