Announcement Announcement Module
Collapse
No announcement yet.
Hibernate query cache org.hibernate.cacheRegion ignored? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate query cache org.hibernate.cacheRegion ignored?

    Hello all - first thanks to the Spring Data team for a remarkable tool. It has saved us tons of time. Kudos!

    I am trying to use query caching with non-CRUD queries in Spring Data. The hitch is that I want to have a separate cache region for each query. The reason is that I have to keep cache in sync between two unrelated systems (the other system does not use Spring or Hibernate), so I need to be able to find the cache for each individual query.

    Here's an example:

    Code:
    @Query("select s from State s where s.abbreviation = :abbreviation")
    @QueryHints({@QueryHint(name = "org.hibernate.cacheable", value = "true"),
       @QueryHint(name = "org.hibernate.cacheRegion", value = "StateRepository.findByAbbreviation")})
    public State findByAbbreviation(@Param("abbreviation") String abbreviation);
    Both "hibernate.cache.use_second_level_cache" and "hibernate.cache.use_query_cache" are set to true in the application context.

    The cache region is defined in ehcache.xml:

    Code:
    <cache
    	name="StateRepository.findByAbbreviation"
    	maxEntriesLocalHeap="1000"
    	eternal="false"
    	overflowToDisk="false"
    	timeToLiveSeconds="0"
    	timeToIdleSeconds="86400">
    	<cacheEventListenerFactory
    		class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
    		properties="replicateAsynchronously=true, replicatePuts=false, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true" />
    </cache>
    It seems that query caching is working, but it Hibernate is using the default query cache region "org.hibernate.cache.StandardQueryCache". Could Spring Data be somehow ignoring the "org.hibernate.cacheRegion" query hint? Or am I doing it wrong?

    Thanks in advance for any help!

    Darrell Burgan
Working...
X