[jBPM] - LocalTaskService keep using one Entity Manager, Breaks when Database is Restarted
by Thomas Setiabudi
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion
"LocalTaskService keep using one Entity Manager, Breaks when Database is Restarted"
To view the discussion, visit: https://community.jboss.org/message/832416#832416
--------------------------------------------------------------
Hi,
This is similar post to https://community.jboss.org/thread/231488?tstart=0 https://community.jboss.org/thread/231488?tstart=0
Only that it discuss about LocalTaskService here
I use JBPM5.4.Final, and Drools-Spring 5.4.Final in a Web Application.
I create Stateful Knowledge Session and LocalTaskService in the Spring config file, they are created once for the rest of the web application life.
Everything works fine, until the Database Server, MS SQL Server 2008, is restarted.
Which then break the Stateful Knowledge Session and LocalTaskService.
After looking at the LocalTaskService code here
https://github.com/droolsjbpm/jbpm/blob/5.4.x/jbpm-human-task/jbpm-human-... https://github.com/droolsjbpm/jbpm/blob/5.4.x/jbpm-human-task/jbpm-human-...
Local Task Service has TaskServiceSession and then TaskServiceSession has TaskPersistenceManager which contain an EntityManager.
The problem is this EntityManager is acquired from EntityManagerFactory just exactly once.
when the database connection is no longer valid (Because of Database Server restart), it will still use the same EntityManager which will of course throw exception.
My question is, is it a bug? or I use these LocalTaskService Wrongly?
Currently, to keep my application running, I create another class that implements TaskService, and have all the code just like LocalTaskService, the difference is I add a check before doing anything about the task.
This is a sample code:
public void addTask(Task task, ContentData content) {
checkEntityManagerFactory();
session.addTask(task, content);
}
and the checkEntityManagerFactory() implementation:
public void checkEntityManagerFactory() {
if (session != null) {
try {
Query query = session.getTaskPersistenceManager()
.createNewQuery("SELECT 1 FROM Task WHERE id = 0 ");
query.getResultList();
} catch (Throwable e) {
session = service.createSession();
}
} else {
session = service.createSession();
}
}
execute simple select query, when that query throws exception, that means its time to get new EntityManager which in this case is create new TaskServiceSession.
Is it the correct way to do this?
Will this issue fixed in JBPM 6 ?
Any help is appreciated.
Regards,
Thomas Setiabudi
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/832416#832416]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 8 months
[jBPM] - DroolsSpringJpaManager breaks when Database Server is restarted, how to handle it?
by Thomas Setiabudi
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion
"DroolsSpringJpaManager breaks when Database Server is restarted, how to handle it?"
To view the discussion, visit: https://community.jboss.org/message/832415#832415
--------------------------------------------------------------
Hi,
I use JBPM5.4.Final, and Drools-Spring 5.4.Final in a Web Application.
I create Stateful Knowledge Session and LocalTaskService in the Spring config file, they are created once for the rest of the web application life.
Everything works fine, until the Database Server, MS SQL Server 2008, is restarted.
Which then break the Stateful Knowledge Session and LocalTaskService.
After looking into the code, I found that when we declare Stateful Knowledge Session like this:
<drools-spring:ksession id="ksession1" type="stateful"
kbase="kbase1">
<drools-spring:configuration>
<drools-spring:jpa-persistence>
<drools-spring:transaction-manager
ref="transactionManager" />
<drools-spring:entity-manager-factory
ref="entityManagerFactory" />
</drools-spring:jpa-persistence>
</drools-spring:configuration>
</drools-spring:ksession>
Eventhough we give it EntityManagerFactory, the code inside DroolsSpringJpaManager will try to get EntityManager just once
this is how the code looks inside org.drools.container.spring.beans.persistence.DroolsSpringJpaManager:
https://github.com/droolsjbpm/droolsjbpm-integration/blob/5.5.x/drools-co... https://github.com/droolsjbpm/droolsjbpm-integration/blob/5.5.x/drools-co...
Look at the implementation of getApplicationScopedPersistenceContext starting from line 64
The problem with this implementation is EntityManagerFactory used exactly just one time to get an EntityManager, even when the database connection is no longer valid, it will still use the same EntityManager which will of course throw exception.
My question is, is it a bug? or I use these Stateful Knowledge Session Wrongly?
Currently, to keep my application running, I modified DroolsSpringJpaManager at getApplicationScopedPersistenceContext():
If the appScopedEntityManager is not null, then execute simple select query, when that query throws exception, that means its time to get new EntityManager from the EntityManagerFactory.
It may be an ugly fix, but thats why I need to clarify this issue.
here is the code:
public PersistenceContext getApplicationScopedPersistenceContext() {
boolean refreshEntityManager = false;
if (this.appScopedEntityManager != null) {
try {
Query query = this.appScopedEntityManager
.createQuery("SELECT 1 FROM Task WHERE id = 0 ");
query.getResultList();
// System.out.println("Query Result: " + String.valueOf(a));
} catch (Throwable e) {
// System.out.println(e.getMessage());
refreshEntityManager = true;
}
}
if (refreshEntityManager == true) {
// System.out.println("Refreshing EM....");
EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager
.getResource(this.emf);
this.appScopedEntityManager = this.emf.createEntityManager();
emHolder = new EntityManagerHolder(this.appScopedEntityManager);
internalAppScopedEntityManager = true;
this.env.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER,
emHolder.getEntityManager());
// System.out.println("Done Refreshing EM....");
} else {
if (this.appScopedEntityManager == null) {
// Use the App scoped EntityManager if the user has provided it,
// and
// it is open.
this.appScopedEntityManager = (EntityManager) this.env
.get(EnvironmentName.APP_SCOPED_ENTITY_MANAGER);
if (this.appScopedEntityManager != null
&& !this.appScopedEntityManager.isOpen()) {
throw new RuntimeException(
"Provided APP_SCOPED_ENTITY_MANAGER is not open");
}
if (this.appScopedEntityManager == null) {
EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager
.getResource(this.emf);
if (emHolder == null) {
this.appScopedEntityManager = this.emf
.createEntityManager();
emHolder = new EntityManagerHolder(
this.appScopedEntityManager);
TransactionSynchronizationManager.bindResource(
this.emf, emHolder);
internalAppScopedEntityManager = true;
} else {
this.appScopedEntityManager = emHolder
.getEntityManager();
}
this.env.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER,
emHolder.getEntityManager());
}
}
if (TransactionSynchronizationManager.isActualTransactionActive()
&& isJTA) {
this.appScopedEntityManager.joinTransaction();
}
}
return new JpaPersistenceContext(this.appScopedEntityManager, isJTA);
}
Is it the correct way to do this?
Will this issue fixed in JBPM 6 ?
Any help is appreciated.
Regards,
Thomas Setiabudi
Note:
Attached server log that shows:
1. the error after database is restarted and I try to call start process on the ksession.
2. the error after the first error happen and I try to call start process on the ksession again.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/832415#832415]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 8 months
[jBPM] - Designer - Mixed up global/input/output variables in imported processes
by Olaf Sebelin
Olaf Sebelin [https://community.jboss.org/people/osebelin] created the discussion
"Designer - Mixed up global/input/output variables in imported processes"
To view the discussion, visit: https://community.jboss.org/message/832094#832094
--------------------------------------------------------------
Hi,
we are migrating from using the drools eclipse BPMN2 modeler to the designer 2.4 war. When I import the processes into the guvnor, edit them in the designer and save and export them they fail to execute in the drools runtime.
I narrowed the problem down to global variables, data input and output variables that have the same name. They will get mixed up leading to missing <bpmn2:dataInputAssociation> elements.
This is visible in the editor for data assignments for work items. If I try to map e.g.
* the global variable 'acl' to the input parameter 'acl' and
* the output parameter 'acl' to the global variable 'acl',
they get mixed up. If I open the drop down list again, ist is always the global variable that is selected. This occurs in both the "From Object" and "To Object" drop down list.
This leads to a missing <bpmn2:dataInputAssociation> for the 'acl' variable in the generated BPMN2. The <bpmn2:dataOutputAssociation> for the 'acl' output parameter gets generated correctly however.
Is this an error in the designer or is it prohibited to use the same variable names, even if it was working fine in the eclipse modeler? Is there a way to work around this using the designer?
Thanks
Olaf
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/832094#832094]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 8 months