Using 'DisposeSessionTransactionSynchronization' and 'DestroySessionTransactionSynchronization' in the same code of jBPM6 causes the removal of KieSession twice

Solution Unverified - Updated -

Issue

  • This issue is observed while using PerRequestRuntimeManager strategy and when DisposeSessionTransactionSynchronization and DestroySessionTransactionSynchronization both are registered in the same code, and when Spring is used.
        registerDisposeCallback(runtime, new DisposeSessionTransactionSynchronization(this, runtime));
        registerDisposeCallback(runtime, new DestroySessionTransactionSynchronization(runtime.getKieSession()));

It has been observed that When transaction is committing, the DestroySessionTransactionSynchronization is executed first , then it destroys the KieSession, and remove the SessionInfo in the current EntityManager. Then DisposeSessionTransactionSynchronization gets executed, which always seem to try and destroy the KieSession again. In this current situation this operation fails while removing the detached SessionInfo.

  • Below is the stack trace of the exception being thrown.
...
java.lang.IllegalArgumentException: Removing a detached instance org.drools.persistence.info.SessionInfo#1
    at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:67)
    at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:107)
    at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
    at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:956)
    at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:935)
    at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:905)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:334)
    at com.sun.proxy.$Proxy75.remove(Unknown Source)
    at org.drools.persistence.jpa.JpaPersistenceContext.remove(JpaPersistenceContext.java:52)
    at org.drools.persistence.SingleSessionCommandService.destroy(SingleSessionCommandService.java:415)
    at org.drools.core.command.runtime.DestroySessionCommand.execute(DestroySessionCommand.java:36)
    at org.drools.core.command.runtime.DestroySessionCommand.execute(DestroySessionCommand.java:22)
    at org.drools.core.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36)
    at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)
    at org.drools.persistence.SingleSessionCommandService$TransactionInterceptor.execute(SingleSessionCommandService.java:502)
    at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)
    at org.drools.persistence.jpa.OptimisticLockRetryInterceptor.execute(OptimisticLockRetryInterceptor.java:73)
    at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:377)
    at org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession.destroy(CommandBasedStatefulKnowledgeSession.java:254)
    at org.jbpm.runtime.manager.impl.PerRequestRuntimeManager.disposeRuntimeEngine(PerRequestRuntimeManager.java:95)
    at org.jbpm.runtime.manager.impl.tx.DisposeSessionTransactionSynchronization.afterCompletion(DisposeSessionTransactionSynchronization.java:43)
    at org.drools.persistence.TransactionSynchronizationContainer.afterCompletion(TransactionSynchronizationContainer.java:26)
    at org.kie.spring.persistence.SpringTransactionSynchronizationAdapter.afterCompletion(SpringTransactionSynchronizationAdapter.java:37)
    at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:168)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:997)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:972)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:802)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:597)
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:296)
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:189)
...

Environment

  • Red Hat JBoss BPM Suite (BPMS)
    • 6.0.3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.