Bulk queries in Hibernate 3.3 + Jboss Cache 2.1.1 + Bitronix 1.3.2

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bulk queries in Hibernate 3.3 + Jboss Cache 2.1.1 + Bitronix 1.3.2

Adrian Miron
When a bulk query (like “delete from AnEntity”) is executed, JbossCache complains about the current transaction being invalid. Looks like it expects an ACTIVE tx, but the current one is COMMITED.

By poking around into btm and jboss cache sources, I saw that hibernate registers a synchronization to be executed after the tx completion. It should clear the cache in case of bulk operations. Hibernate delegates to jboss cache for node deletion but jboss cache looks up whatever there is an ongoing global tx. If it finds one, it checks that it is ACTIVE; if not it throws an exception.


I’m not sure yet if I should care about it or not (hibernate just logs it and moves on), but I saw that this is not happening if I use atomikos. Inside atomikos’s afterCompletion the tx context is already cleared and there is no global tx.

The exception:

16:14:56 ERROR (ActionQueue.java:207) - could not release a cache lock
org.hibernate.cache.CacheException: org.jboss.cache.CacheException: Invalid transaction a Bitronix Transaction with GTRID [737072696E672D62746D0000011DDE4D719700000000], status=COMMITTED, 1 resource(s) enlisted (started Thu Nov 27 16:14:56 EET 2008), status = 3
        at org.hibernate.cache.jbc2.util.CacheHelper.removeAll(CacheHelper.java:380)
        at org.hibernate.cache.jbc2.util.CacheHelper.removeAll(CacheHelper.java:360)
        at org.hibernate.cache.jbc2.access.TransactionalAccessDelegate.evictOrRemoveAll(TransactionalAccessDelegate.java:146)
        at org.hibernate.cache.jbc2.access.TransactionalAccessDelegate.evictAll(TransactionalAccessDelegate.java:142)
        at org.hibernate.cache.jbc2.entity.TransactionalAccess.evictAll(TransactionalAccess.java:102)
        at org.hibernate.impl.SessionFactoryImpl.evictEntity(SessionFactoryImpl.java:870)
        at org.hibernate.action.BulkOperationCleanupAction.evictEntityRegions(BulkOperationCleanupAction.java:153)
        at org.hibernate.action.BulkOperationCleanupAction.afterTransactionCompletion(BulkOperationCleanupAction.java:132)
        at org.hibernate.engine.ActionQueue.afterTransactionCompletion(ActionQueue.java:198)
        at org.hibernate.impl.SessionImpl.afterTransactionCompletion(SessionImpl.java:451)
        at org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(JDBCContext.java:252)
        at org.hibernate.transaction.CacheSynchronization.afterCompletion(CacheSynchronization.java:117)
        at bitronix.tm.BitronixTransaction.fireAfterCompletionEvent(BitronixTransaction.java:382)
        at bitronix.tm.BitronixTransaction.commit(BitronixTransaction.java:188)
        at bitronix.tm.BitronixTransactionManager.commit(BitronixTransactionManager.java:96)
        at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1028)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
        at bitronix.JBossCache2Test.testJbossCache2(JBossCache2Test.java:28)
        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:585)
        at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:163)
        at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
        at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
        at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
        at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
        at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
        at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
        at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
        at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
        at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
        at com.intellij.rt.junit4.Junit4TestMethodAdapter.run(Junit4TestMethodAdapter.java:50)
        at junit.textui.TestRunner.doRun(TestRunner.java:116)
        at com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:65)
        at junit.textui.TestRunner.doRun(TestRunner.java:109)
        at com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs(IdeaTestRunner.java:24)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:118)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
        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:585)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: org.jboss.cache.CacheException: Invalid transaction a Bitronix Transaction with GTRID [737072696E672D62746D0000011DDE4D719700000000], status=COMMITTED, 1 resource(s) enlisted (started Thu Nov 27 16:14:56 EET 2008), status = 3
        at org.jboss.cache.interceptors.Interceptor.assertTransactionValid(Interceptor.java:208)
        at org.jboss.cache.interceptors.PessimisticLockInterceptor.lock(PessimisticLockInterceptor.java:428)
        at org.jboss.cache.interceptors.PessimisticLockInterceptor.acquireLocksWithTimeout(PessimisticLockInterceptor.java:399)
        at org.jboss.cache.interceptors.PessimisticLockInterceptor.handleRemoveNodeMethod(PessimisticLockInterceptor.java:274)
        at org.jboss.cache.interceptors.MethodDispacherInterceptor.invoke(MethodDispacherInterceptor.java:108)
        at org.jboss.cache.interceptors.PessimisticLockInterceptor.invoke(PessimisticLockInterceptor.java:81)
        at org.jboss.cache.interceptors.Interceptor.nextInterceptor(Interceptor.java:111)
        at org.jboss.cache.interceptors.MethodDispacherInterceptor.invoke(MethodDispacherInterceptor.java:58)
        at org.jboss.cache.interceptors.Interceptor.nextInterceptor(Interceptor.java:111)
        at org.jboss.cache.interceptors.TxInterceptor.handleNonTxMethod(TxInterceptor.java:456)
        at org.jboss.cache.interceptors.TxInterceptor.handleRemoveNodeMethod(TxInterceptor.java:215)
        at org.jboss.cache.interceptors.MethodDispacherInterceptor.invoke(MethodDispacherInterceptor.java:108)
        at org.jboss.cache.interceptors.Interceptor.nextInterceptor(Interceptor.java:111)
        at org.jboss.cache.interceptors.MethodDispacherInterceptor.invoke(MethodDispacherInterceptor.java:58)
        at org.jboss.cache.interceptors.Interceptor.nextInterceptor(Interceptor.java:111)
        at org.jboss.cache.interceptors.InvocationContextInterceptor.invoke(InvocationContextInterceptor.java:73)
        at org.jboss.cache.invocation.AbstractInvocationDelegate.invoke(AbstractInvocationDelegate.java:123)
        at org.jboss.cache.invocation.AbstractInvocationDelegate.invoke(AbstractInvocationDelegate.java:64)
        at org.jboss.cache.invocation.CacheInvocationDelegate.removeNode(CacheInvocationDelegate.java:420)
        at org.hibernate.cache.jbc2.util.CacheHelper.removeAll(CacheHelper.java:378)
        ... 47 more
Reply | Threaded
Open this post in threaded view
|

Re: Bulk queries in Hibernate 3.3 + Jboss Cache 2.1.1 + Bitronix 1.3.2

Ludovic Orban
Administrator
This looks like an old well-know issue of Hibernate 3.2 and JBC, see http://opensource.atlassian.com/projects/hibernate/browse/HHH-2532 and http://www.jboss.com/index.html?module=bb&op=viewtopic&t=103983

What's puzzling is that you're using Hibernate 3.3 and this issue should have been solved.

I nevertheless think this is still a Hibernate issue because by the time you are in afterCompletion(), any code called should not happen inside of that transaction since the transaction has, by definition, completed (quoting the JBoss forum).

You should report this to the Hibernate devs.