Search code examples
hibernatejpaspring-data-jpahibernate-criteriajpa-criteria

JPA Criteria Query - Set ehcache region name?


I could enable query caching for jpa criteria using below -

javax.persistence.Query regularQuery = em.createQuery(query);
regularQuery.setHint("org.hibernate.cacheable", true);

I also want to specify the cache name for this query, i tried below but its not working.

regularQuery.setHint("org.hibernate.cache.region", "xcain4");

How can I provide the cache name.. any suggestions?


Solution

  • You can use something like this:

    import org.hibernate.jpa.QueryHints;
    
    // ...
    
    javax.persistence.Query regularQuery = em.createQuery(query);
    regularQuery.setHint(QueryHints.HINT_CACHEABLE, true);
    regularQuery.setHint(QueryHints.HINT_CACHE_REGION, "xcain4");
    

    See this part of the hibernate documentation.