Hi everyone,
I'm running into an issue specifying custom region names for my 2nd level entity cache (not the query cache).
I have an entity annotated like below:
Code:
package com.package;
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "myCustomRegion")
public class MyEntity{
//Entity code goes here
}
Below is my hibernate session factory configuration (the memcached properties can be ignored for the purpose of this question IMO):
Code:
<prop key="hibernate.cache.provider_class">com.googlecode.hibernate.memcached.MemcachedCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.memcached.servers">cacheserver.com:11211</prop>
<prop key="hibernate.memcached.cacheTimeSeconds">300</prop>
Now the problem. It seems that the region name being used when hibernate loads and builds all the caches is the fully qualified entity name, which is the default behavior. From my example this would be "com.package.MyEntity". I was expecting it to use the custom region name I provided in the annotation "myCustomRegion". This is the log output (the last line shows the region name):
Code:
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(169) | Automatic flush during beforeCompletion(): disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(173) | Automatic session close at end of transaction: disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(180) | JDBC batch size: 15
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(183) | JDBC batch updates for versioned data: disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(188) | Scrollable result sets: enabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(196) | JDBC3 getGeneratedKeys(): enabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(204) | Connection release mode: auto
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(228) | Maximum outer join fetch depth: 2
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(231) | Default batch fetch size: 1
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(235) | Generate SQL with comments: disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(239) | Order SQL updates by primary key: disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(243) | Order SQL inserts for batching: disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.createQueryTranslatorFactory(410) | Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2011-11-03 10:43:14 INFO [main] ASTQueryTranslatorFactory.<init>(47) | Using ASTQueryTranslatorFactory
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(251) | Query language substitutions: {}
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(256) | JPA-QL strict compliance: disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(261) | Second-level cache: enabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(265) | Query cache: disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.createRegionFactory(395) | Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
2011-11-03 10:43:14 INFO [main] RegionFactoryCacheProviderBridge.<init>(61) | Cache provider: com.googlecode.hibernate.memcached.MemcachedCacheProvider
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(275) | Optimize cache for minimal puts: enabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(284) | Structured second-level cache entries: enabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(313) | Statistics: enabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(317) | Deleted entity synthetic identifier rollback: disabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(332) | Default entity-mode: pojo
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(336) | Named query checking : enabled
2011-11-03 10:43:14 INFO [main] SettingsFactory.buildSettings(340) | Check Nullability in Core (should be disabled when Bean Validation is on): disabled
2011-11-03 10:43:14 INFO [main] SessionFactoryImpl.<init>(199) | building session factory
2011-11-03 10:43:14 INFO [main] MemcachedCacheProvider.start(151) | Starting MemcachedClient...
2011-11-03 10:43:14.549 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=cacheserver.com:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2011-11-03 10:43:14.590 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@537827e9
2011-11-03 10:43:14 INFO [main] MemcachedCacheProvider.buildCache(94) | Building cache for region [com.package.MyEntity]
Am I going about this all wrong? Is what I'm trying to do even possible for the entity cache?
Your help is much appreciated. Thanks.