| When using the Query Cache and caching the following query:
Person person = doInJPA( this::entityManagerFactory, entityManager -> {
return entityManager.createQuery(
"select distinct p " +
"from Person p " +
"join fetch p.phones ph", Person.class)
.setHint( QueryHints.CACHEABLE, Boolean.TRUE )
.getSingleResult();
} );
assertEquals(2, person.getPhones().size());
Everything works fine since the result will contain the `phones` collections, properly initialized. However, when getting the result from the cache:
person = doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.getEntityManagerFactory().getCache().evictAll();
return entityManager.createQuery(
"select distinct p " +
"from Person p " +
"join fetch p.phones ph", Person.class )
.setHint( QueryHints.CACHEABLE, Boolean.TRUE )
.getSingleResult();
} );
assertEquals(
1,
entityManagerFactory().unwrap( SessionFactory.class ).getStatistics().getQueryCacheHitCount()
);
assertEquals( 2, person.getPhones().size() );
A LazyInitializationException is thrown:
|