Hibernate second level caching problem

328 views
Skip to first unread message

Whitney Hunter

unread,
Jan 21, 2014, 5:35:43 PM1/21/14
to haze...@googlegroups.com
I'm trying to upgrade my system from Hazelcast version 1.9.4.4 to version 3.1.3. We use Hazelcast as our Hibernate second-level cache. So when I moved to 3.1.3, I set '

hibernate.cache.region.factory_class' to 'com.hazelcast.hibernate.HazelcastCacheRegionFactory'.

The issue that I am seeing appears to be caused by the fact that we are using native sql calls. It looks like when we do this, Hibernate is telling Hazelcast to invalidate its cache. But some entities are marked as '@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)' .When Hazelcast tries to lock the region it produces the following exception:

java.lang.RuntimeException: java.lang.UnsupportedOperationException: Attempting to lock a read-only cache region: com.onstation.service.eadvantage.pojo.address.State
	at com.onstation.service.fixture.ShopFixture.generateAndAddRandomShop(ShopFixture.java:152)
	at com.onstation.service.fixture.ShopFixture.createAndAddRandomShop(ShopFixture.java:39)
	at com.onstation.ext.report.zip.ZipFileTest.shouldGetShopFromDealerAndConsumerZipMap(ZipFileTest.java:33)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
	at org.apache.maven.surefire.junitcore.ClassDemarcatingRunner.run(ClassDemarcatingRunner.java:58)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:24)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
	at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.UnsupportedOperationException: Attempting to lock a read-only cache region: com.onstation.service.eadvantage.pojo.address.State
	at com.hazelcast.hibernate.access.ReadOnlyAccessDelegate.lockRegion(ReadOnlyAccessDelegate.java:60)
	at com.hazelcast.hibernate.region.EntityRegionAccessStrategyAdapter.lockRegion(EntityRegionAccessStrategyAdapter.java:70)
	at org.hibernate.action.BulkOperationCleanupAction$EntityCleanup.<init>(BulkOperationCleanupAction.java:208)
	at org.hibernate.action.BulkOperationCleanupAction$EntityCleanup.<init>(BulkOperationCleanupAction.java:202)
	at org.hibernate.action.BulkOperationCleanupAction.<init>(BulkOperationCleanupAction.java:121)
	at org.hibernate.engine.query.NativeSQLQueryPlan.coordinateSharedCacheCleanup(NativeSQLQueryPlan.java:176)
	at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:189)
	at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1300)
	at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:365)
	at com.onstation.service.impl.security.Writer.addRole(Writer.java:38)
	at com.onstation.service.impl.security.AuthorizationServiceImpl.addRole(AuthorizationServiceImpl.java:44)
	at sun.reflect.GeneratedMethodAccessor175.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at com.sun.proxy.$Proxy112.addRole(Unknown Source)
	at com.onstation.service.fixture.ShopFixture.addShopAndUser(ShopFixture.java:483)
	at com.onstation.service.fixture.ShopFixture.generateAndAddRandomShop(ShopFixture.java:148)
	... 34 more

The only way I've found to avoid the issue is either to disable second level caching or to remove @Cache annotation (which stops caching as well). The code worked fine in 1.9.4.4. Any thoughts on what I can do in 3.1.3 short of turning off caching?

Thanks,

Whitney Hunter

kraym...@gmail.com

unread,
Feb 27, 2014, 11:00:36 AM2/27/14
to haze...@googlegroups.com
Did you ever find the cause of this?
Reply all
Reply to author
Forward
0 new messages