@Test public void shouldRetrieveRef(){ Person p = em.getReference(Person.class, 1l); p.setLastName("ronak"); Assertions.assertThat(p.getClass()).isNotInstanceOf(Person.class); Assertions.assertThat(p.getId()).isEqualTo(1l); PersistenceUtil persistenceUtil = Persistence.getPersistenceUtil(); log.info("{}",persistenceUtil.isLoaded(p)); }
@Test public void shouldRetrieveFind(){ Person p = em.find(Person.class, 1l); p.setLastName("ronak"); Assertions.assertThat(p.getClass()).isNotInstanceOf(Person.class); Assertions.assertThat(p.getId()).isEqualTo(1l); PersistenceUtil persistenceUtil = Persistence.getPersistenceUtil(); log.info("{}",persistenceUtil.isLoaded(p)); }
public List<School> findall () { System.out.println("loading schools from table SCHOOL"); List <School> schools = (List<School>) em.createQuery("select s from School s").getResultList(); PersistenceUtil util = Persistence.getPersistenceUtil(); boolean isObjectLoaded = util.isLoaded(schools.get(0)); boolean isManaged = em.contains(schools.get(0)); //force lazy loading befor the end of the session schools.get(0).getAcademicYears().get(0).getYear(); return schools; }
public static PersistenceUtil getPersistenceUtil() { return Persistence.getPersistenceUtil(); }
public PersistenceUtil util() { return Persistence.getPersistenceUtil(); }