em.close();
}
private void verifyIsLoadedLazyState(boolean loaded) {
PersistenceUtil putil = Persistence.getPersistenceUtil();
EntityManager em = emf.createEntityManager();
LazyEntity le = createLazyEntity();
// Vfy LoadState is true for the unmanaged entity via
// PersistenceUtil
assertEquals(true, putil.isLoaded(le));
assertEquals(true, putil.isLoaded(le,"id"));
em.getTransaction().begin();
em.persist(le);
em.getTransaction().commit();
em.clear();
// Use find or getReference based upon expected state
if (loaded)
le = em.find(LazyEntity.class, le.getId());
else
le = em.getReference(LazyEntity.class, le.getId());
assertEquals(loaded, putil.isLoaded(le));
assertEquals(loaded, putil.isLoaded(le, "id"));
// Name is lazy fetch so it should not be loaded
assertEquals(false, putil.isLoaded(le, "name"));
assertEquals(loaded, putil.isLoaded(le, "lazyEmbed"));
assertEquals(true, putil.isLoaded(le, "transField"));
em.close();
}