5

I want to enable hibernate query cache. I understand 'Query' and 'Criteria' has a function called 'setCachable' in order 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;
user459811
  • 2,874
  • 10
  • 37
  • 63

0 Answers0