public boolean isLoaded(Object entity) { // added log message to help with HHH-7454, if state == LoadState,NOT_LOADED, returning true // or false is not accurate. log.debug( "PersistenceUnitUtil#isLoaded is not always accurate; consider using EntityManager#contains instead"); return PersistenceUtilHelper.isLoaded(entity) != LoadState.NOT_LOADED; }
public boolean isLoaded(Object entity, String attributeName) { // added log message to help with HHH-7454, if state == LoadState,NOT_LOADED, returning true // or false is not accurate. log.debug( "PersistenceUnitUtil#isLoaded is not always accurate; consider using EntityManager#contains instead"); LoadState state = PersistenceUtilHelper.isLoadedWithoutReference(entity, attributeName, cache); if (state == LoadState.LOADED) { return true; } else if (state == LoadState.NOT_LOADED) { return false; } else { return PersistenceUtilHelper.isLoadedWithReference(entity, attributeName, cache) != LoadState.NOT_LOADED; } }
@Test public void testIsLoadedWithoutReferenceOnKnownClass() { final Author entity = new Author(); assertEquals( LoadState.UNKNOWN, PersistenceUtilHelper.isLoadedWithoutReference(entity, "attribute", cache)); }
@Test public void testIsLoadedWithReferenceOnUnknownClass() { final Object entity = new Object(); assertEquals( LoadState.UNKNOWN, PersistenceUtilHelper.isLoadedWithReference(entity, "attribute", cache)); }
@Test public void testIsLoadedOnKnownClass() { final Author entity = new Author(); assertTrue(Persistence.getPersistenceUtil().isLoaded(entity)); assertEquals(LoadState.UNKNOWN, PersistenceUtilHelper.isLoaded(entity)); }