Enabling Query Caching with CriteriaQuery. Is it possible?

I want to enable hibernate cache. I understand that "Query" and "Criteria" have a "setCachable" function to mark the query as cacheable. Is there a way to do this with "CriteriaQuery"?

    CriteriaQuery<UserEntity> criteria = entityManager.getCriteriaBuilder().createQuery(UserEntity.class);
    Root <UserEntity> contactRoot = criteria.from(UserEntity.class);
    criteria.select(contactRoot);

    Predicate predicate = entityManager.getCriteriaBuilder().equal(
            contactRoot.get("username"), username);
    criteria.where(predicate);

    UserEntity contact = entityManager.createQuery(criteria).getSingleResult();

    return contact;

      

+3


source to share





All Articles