Home > front end >  JPA Criteria Query - Set ehcache region name?
JPA Criteria Query - Set ehcache region name?

Time:10-30

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?

CodePudding user response:

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.

  • Related