Eclipselink cache is not used for Criteria API queries

714 views Asked by At

I am using Criteria API for creation of queries which are usually not using PK as identifier. I am not able to force eclipselink store result to cache.

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Book> criteriaQuery = builder.createQuery(MetadataTextValue.class);
Root<Book> root = criteriaQuery.from(MetadataTextValue.class);
criteriaQuery = criteriaQuery.where(builder.equal(root.get("value"),value.getValue()));
TypedQuery<Book> typedQuery = em.createQuery(criteriaQuery);
MetadataTextValue metadataTextValue = typedQuery.getSingleResult();

But it works for:

    Query query = entityManager.createQuery("select m from MetadataTextValue m where m.value = :value");
    query.setParameter("value",value.getValue());
    return (MetadataTextValue)query.getSingleResult();

So there should not be problem with the entity and value itself. I tried to debug Eclipselink search and when using criteria API, after first cache miss result is added to cache, but next search for same value is again cache miss, but is not added.

0

There are 0 answers