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

Kris Verlaenen kris.verlaenen at cs.kuleuven.be
Mon Jul 26 09:32:46 EDT 2010


Rory,

I would recommend using 5.1.x if you plan to use persistence, as that 
probably already has some fixes in it compared to 5.0.x.  So let's get this 
working with 5.1 first ;)

Easiest is to simply take a look at the tests if you are looking for a 
working example.  For example:
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-persistence-jpa/src/test/java/org/drools/persistence/session/PersistentStatefulSessionTest.java
This contains numerous tests on persistence and working examples on how to 
setup up your data source, correctly setup up your environment, etc.  It's 
usually easier to modify a working example according to your requirements 
than to start from scratch ;)  It also contains the necessary 
META-INF/persistence.xml, META-INF/orm.xml and jndi.properties in the 
resources folder:
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-persistence-jpa/src/test/resources/

Let me know if you still have issues getting persistence to work.  If you 
think you've encountered an issue, could you try attaching the process xml 
and java test code?  That would make it a lot easier to verify what is going 
on exactly and fix if necessary.

Kris

----- Original Message ----- 
From: "Rory Farrell" <rjf at bellsouth.net>
To: "Rules Users List" <rules-users at lists.jboss.org>
Sent: Friday, July 23, 2010 11:02 PM
Subject: [rules-users] Persistence with Drools 5.0.1 (was Persistence 
withDrools 5.1.0.M2)


> 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
>


--------------------------------------------------------------------------------


> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the rules-users mailing list