em.close();
}
private void verifyIsLoadedLazyState(LoadState state) {
ProviderUtil pu = getProviderUtil();
EntityManager em = emf.createEntityManager();
LazyEntity le = createLazyEntity();
// Vfy LoadState is unknown for the unmanaged entity
assertEquals(LoadState.UNKNOWN, pu.isLoaded(le));
assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(le,
"id"));
assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(le,
"id"));
em.getTransaction().begin();
em.persist(le);
em.getTransaction().commit();
em.clear();
// Use find or getReference based upon expected state
if (state == LoadState.LOADED)
le = em.find(LazyEntity.class, le.getId());
else
le = em.getReference(LazyEntity.class, le.getId());
assertEquals(state, pu.isLoaded(le));
assertEquals(state, pu.isLoadedWithReference(le,
"id"));
assertEquals(state, pu.isLoadedWithoutReference(le,
"id"));
// Name is lazy fetch so it should not be loaded
assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithReference(le,
"name"));
assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithoutReference(le,
"name"));
assertEquals(state, pu.isLoadedWithReference(le,
"lazyEmbed"));
assertEquals(state, pu.isLoadedWithoutReference(le,
"lazyEmbed"));
// lazyEmbedColl is lazy fetch so it should not be loaded
assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithReference(le,
"lazyEmbedColl"));
assertEquals(LoadState.NOT_LOADED, pu.isLoadedWithoutReference(le,
"lazyEmbedColl"));
assertEquals(LoadState.UNKNOWN, pu.isLoadedWithReference(le,
"transField"));
assertEquals(LoadState.UNKNOWN, pu.isLoadedWithoutReference(le,
"transField"));
em.close();
}