[rules-users] Persistence with Drools 5.0.1 (was Persistence with Drools 5.1.0.M2)

Rory Farrell rjf at bellsouth.net
Fri Jul 23 17:02:17 EDT 2010


Hi, I was trying to get persistence working in Drools 5.1.0.M2 but ran 
into some issues:

http://drools-java-rules-engine.46999.n3.nabble.com/Persistence-with-Drools-5-1-0-M2-td973691.html#none

I decided to try with 5.0.1 to see if I had any better luck.  I ran into 
the same problem:

java.lang.NullPointerException
	at
org.drools.persistence.processinstance.JPAWorkItemManager.completeWorkItem(JPAWorkItemManager.java:85)

Line 85 is:

workItemInfo = em.find(WorkItemInfo.class, id);

The JPAWorkItemManager tries to retrieve the EntityManager from the
environment:

EntityManager em = (EntityManager)
this.workingMemory.getEnvironment().get( EnvironmentName.ENTITY_MANAGER );

and the EntityManager is not in the environment.

The EntityManagerFactory is in the environment and I see where the
SingleSessionCommandService class uses the factory to instantiate an
EntityManager, but it never gets put in the environment for the
JPAWorkItemManager to retrieve it.

I was using the UIWorkItemHandler from the example applications.  I 
wrote a dummy WorkItemHandler to replace the UIWorkItemHandler:

public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
     Map<String, Object> results = new HashMap<String, Object>();
     System.out.println("Before complete work item");
     ksession.getWorkItemManager().completeWorkItem(workItem.getId(), 
results);
     System.out.println("After complete work item");
}

This fixed the NullPointerException but the role flow process was not 
detecting that the work item had been completed.  I debugged into the 
completeWorkItem code and I found that JPAWorkItemManager class called 
the ProcessInstance.signalEvent method with "workItemCompleted" but the 
WorkflowProcessInstanceImpl.signalEvent method found no eventListeners 
for that type.

I can see the eventListeners for "workItemCompleted" and for 
"workItemAborted" when I do a ksession.update but the eventListeners are 
not there when my WorkItemHandler is called.

This only happens when the flow is resumed from an Event Wait flow by 
updating a FactHandle.  If the flow goes directly to the Human Task node 
then the workItem is completed correctly.

I attached a screenshot of the rule flow.  If there are no missing 
certification when the process is started then the Human Task is 
completed successfully.  If there are missing certifications and then 
the constraint is satisfied by updating a FactHandle then the workItem 
is not completed correctly and the flow does not proceed to sending the 
email.

This all works correctly if I don't try to persist the rule flow.

Hopefully someone can provide some insight as to what is going on here.

Regards,
Rory
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ruleflow.png
Type: image/png
Size: 21336 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20100723/d577aa8d/attachment.png 


More information about the rules-users mailing list