Search in sources :

Example 1 with ParentCachedEntity

use of com.haulmont.cuba.testmodel.entity_cache.ParentCachedEntity in project cuba by cuba-platform.

the class EntityCacheTestClass method testAdditionalParametersUsedDuringLazyLoading.

@Test
public void testAdditionalParametersUsedDuringLazyLoading() {
    try {
        provider.setParam("ONE");
        ParentCachedEntity parent;
        try (Transaction tx = cont.persistence().createTransaction()) {
            Query query = cont.entityManager().createQuery("select p from test$ParentCachedEntity p where p.id = :id");
            query.setParameter("id", cachedParent.getId());
            parent = (ParentCachedEntity) query.getResultList().get(0);
            javax.persistence.EntityManager em = cont.entityManager().getDelegate();
            assertNotNull(parent);
            List<ChildCachedEntity> children = parent.getChildren();
            assertNotNull(children);
            /* Next line checks that changes from eclipselink 2.7.3-19-cuba 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);
    }
}
Also used : Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query) TypedQuery(com.haulmont.cuba.core.TypedQuery) ChildCachedEntity(com.haulmont.cuba.testmodel.entity_cache.ChildCachedEntity) ParentCachedEntity(com.haulmont.cuba.testmodel.entity_cache.ParentCachedEntity)

Aggregations

Query (com.haulmont.cuba.core.Query)1 Transaction (com.haulmont.cuba.core.Transaction)1 TypedQuery (com.haulmont.cuba.core.TypedQuery)1 ChildCachedEntity (com.haulmont.cuba.testmodel.entity_cache.ChildCachedEntity)1 ParentCachedEntity (com.haulmont.cuba.testmodel.entity_cache.ParentCachedEntity)1