Running JBoss 6.0. Somewhere inside running JTA transaction:
@Override
public void stopProcess(PropertyObject object)
{
StatefulKnowledgeSession ksession =
ProcessHelper.loadSession(Registry.get().getMainProcessName(),
object.getKnowledgeSessionId());
ksession.abortProcessInstance(object.getProcessInstanceId());
}
aborting process leads to org.hibernate.StaleObjectStateException:
WARN [com.arjuna.ats.arjuna] ARJUNA-12125
TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple<
0:ffffc0a801e8:126a:4d3fd283:3d,
org.hibernate.transaction.synchronization.HibernateSynchronizationImpl@1fa8761
: javax.persistence.OptimisticLockException:
org.hibernate.StaleObjectStateException: Row was updated or deleted by
another transaction (or unsaved-value mapping was incorrect):
[org.drools.persistence.session.SessionInfo#13]
at
org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:1243)
[:3.6.0.Final]
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1166)
[:3.6.0.Final]
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
[:3.6.0.Final]
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
[:3.6.0.Final]
at
org.hibernate.ejb.AbstractEntityManagerImpl$3.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1067)
[:3.6.0.Final]
at
org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:122)
[:3.6.0.Final]
at
org.hibernate.transaction.synchronization.HibernateSynchronizationImpl.beforeCompletion(HibernateSynchronizationImpl.java:51)
[:3.6.0.Final]
at
com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:97)
[:6.0.0.20101110-CR1]
at
com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:274)
[:6.0.0.20101110-CR1]
at
com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:94)
[:6.0.0.20101110-CR1]
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:159)
[:6.0.0.20101110-CR1]
at
com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1156)
[:6.0.0.20101110-CR1]
at
com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:119)
[:6.0.0.20101110-CR1]
at
com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
[:6.0.0.20101110-CR1]
at
org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:162)
[:6.0.0.20101110-CR1]
at
com.infotech.web.util.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:53)
[:]
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274)
[:6.0.0.20101110-CR1]
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
[:6.0.0.20101110-CR1]
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
[:6.0.0.20101110-CR1]
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
[:6.0.0.20101110-CR1]
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)
[:6.0.0.20101110-CR1]
at
org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)
[:1.1.0.Final]
at
org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)
[:1.1.0.Final]
at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)
[:6.0.0.20101110-CR1]
at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)
[:6.0.0.20101110-CR1]
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
[:6.0.0.20101110-CR1]
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
[:6.0.0.20101110-CR1]
at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
[:6.0.0.20101110-CR1]
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[:6.0.0.20101110-CR1]
at
org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
[:6.0.0.20101110-CR1]
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
[:6.0.0.20101110-CR1]
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
[:6.0.0.20101110-CR1]
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
[:6.0.0.20101110-CR1]
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
[:6.0.0.20101110-CR1]
at java.lang.Thread.run(Unknown Source) [:1.6.0_22]
Caused by: org.hibernate.StaleObjectStateException: Row was updated or
deleted by another transaction (or unsaved-value mapping was incorrect):
[org.drools.persistence.session.SessionInfo#13]
at
org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1932)
[:3.6.0.Final]
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2576)
[:3.6.0.Final]
at
org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2476)
[:3.6.0.Final]
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2803)
[:3.6.0.Final]
at
org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)
[:3.6.0.Final]
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
[:3.6.0.Final]
at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
[:3.6.0.Final]
at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
[:3.6.0.Final]
at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
[:3.6.0.Final]
at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
[:3.6.0.Final]
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
[:3.6.0.Final]
at
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
[:3.6.0.Final]
at
org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:117)
[:3.6.0.Final]
... 29 more
Problem arises only when trying to abort process. Other things are
working: process executes, workItems are created etc.
What is the other transaction that updates the SessionInfo object? Why
doesn't ksession.abortProcessInstance(...) run in my current transaction?
Following helper methods are used in the code above:
public static StatefulKnowledgeSession loadSession(String process, int
sessionId)
{
try
{
KnowledgeBuilder kbuilder = getKnowledgeBuilder(process);
Environment env = buildEnvironment();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession =
JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null,
env);
registerWorkItemHandlers(ksession);
return ksession;
}
catch (Exception ex) {...}
}
public static KnowledgeBuilder getKnowledgeBuilder(String process)
{
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(process,
ProcessHelper.class), ResourceType.DRF);
if (kbuilder.hasErrors())
{
for (KnowledgeBuilderError error : kbuilder.getErrors())
{
System.out.println(error);
}
throw new IllegalStateException("Error building kbase!");
}
return kbuilder;
}
public static Environment buildEnvironment() throws NamingException
{
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("org.drools.persistence.jpa");
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
return env;
}