use of com.haulmont.cuba.core.model.entity_cache.ParentCachedEntity in project jmix by jmix-framework.
the class EntityCacheTestClass method testAdditionalParametersUsedDuringLazyLoading.
@Test
public void testAdditionalParametersUsedDuringLazyLoading() {
// make sure that entity cache enabled for current entities
assertTrue(Boolean.parseBoolean(env.getProperty("eclipselink.cache.shared.test$ChildCachedEntity")));
assertTrue(Boolean.parseBoolean(env.getProperty("eclipselink.cache.shared.test$ParentCachedEntity")));
provider.setParam(null);
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().find(ParentCachedEntity.class, cachedParent.getId());
fail("Query should throw exception without additional parameter");
} catch (QueryException e) {
assertTrue(e.getMessage().contains("No value was provided for the session property [testAdditional]"));
}
provider.setParam("ONE");
try (Transaction tx = persistence.createTransaction()) {
Query query = persistence.getEntityManager().createQuery("select p from test$ParentCachedEntity p where p.id = :id");
query.setParameter("id", cachedParent.getId());
ParentCachedEntity parent = (ParentCachedEntity) query.getResultList().get(0);
javax.persistence.EntityManager em = persistence.getEntityManager().getDelegate();
assertNotNull(parent);
List<ChildCachedEntity> children = parent.getChildren();
assertNotNull(children);
/* Next line checks that changes from eclipselink 2.7.9-6-jmix (Haulmont/jmix-data#107) works:
* DatabaseValueHolder passes additional criteria parameters using CubaUtil.
* Entity in shared cache has no access to ClientSession with additional criteria parameters
* so they has to be passed using another way.
*
* otherwise it will be exception:
* org.eclipse.persistence.exceptions.QueryException:
* Exception Description: No value was provided for the session property [testAdditional]
*/
assertEquals(1, children.size());
tx.commit();
} finally {
provider.setParam(null);
}
}
Aggregations