[rules-users] Problem with JPA session persistence in Drools Flow (5.0.1)

Kris Verlaenen kris.verlaenen at cs.kuleuven.be
Fri Sep 4 09:06:51 EDT 2009


That NPE seems to be an error in the marshaling of the session.  Do you
have a simple test case that you can send me so we can use that to
reproduce this issue (I noticed you are extending the order example, but
you seem to have introduced a few new classes and probably some rules as
well)?

Regarding the session marshaling, it persists its entire internal state.
 So that includes all running process instances, all data in the working
memory (although that is configurable through a strategy) and the
internal state (agenda etc.).  This does not include the knowledge base
or external components, like for example work item handlers.

The current human task handler implementation does indeed not support
restoring after failure, as the event listeners are not re-registered. 
A more fail-safe implementation, for example registering the necessary
listeners upon initialization or using a fail-safe protocol like JMS
should be used for that.  If I remember correctly, a community member is
already looking into that.

Kris

Quoting SBalakrishnan <Sanjay.Balakrishnan at fnis.com>:

> 
> Hi,
> 
> 
> Looks like this issue and related problems
> have become a show stopper for us.
> 
> 
> 
> The UseCase we are trying to address is recreating inflight Human
> Tasks
> after the engine has been stopped (could be a shutdown or server
> error scenario). 
> 
> It was noticed that if we do not insert any global variables in the
> session
> ,then we do not see the earlier reported Null pointer exception and
> the
> session load from
> the previous session id goes through.
> (Code snippet below)
> 
> 
> But then I come to the next question, what type of information  does
> the
> session
> carry over (could not find information on it) . Is it only global
> variables
> ?
> 
> 
> Also what happens to the informaton tied to the registered handlers.
> In this case  all the task event registrations in the human task
> handler(CommandBasedWSHumanTaskHandler)
> are lost.As a  result it is noticed that it leads to tasks getting
> completed
> on the
> MinaTaskServer, but the Process Flow not knowing about it and leading
> to
> workItems
> remaining open (orphan items).
> 
> Please do let us know if you have run into this issue or if you have
> other inputs.
> 
> 
> Thanks in advance
> Sanjay
> 
> /*Commented code to bypass first issue:-*/
> 
> Order order = new Order();
> order.setOrderId("Order-" + ++orderCounter);
> order.setCustomerId(customerIdTextField.getText());
> ItemInfo itemInfo = (ItemInfo) itemComboBox.getSelectedItem();
> order.addOrderItem(itemInfo.getItemId(), new
> Integer(amountTextField.getText()), itemInfo.getPrice());
> 
> AppData testAppData = new AppData();
> testAppData.setRelationShipPricing("Pricing");
> 
> //Commented global variable insert
> //Commented ksession.insert(testAppData);
> 
> Map<String, Object> parameters = new HashMap<String, Object>();
> parameters.put("order", order);
> parameters.put("email", emailTextField.getText());
> WorkflowProcessInstance testProcess = (WorkflowProcessInstance)
> ksession.startProcess("RuleSetExample", parameters);
> ksession.fireAllRules();
> this._processId= testProcess.getId();
> 
> /*Commented code to bypass first issue:-*/
> 
> 
> SBalakrishnan wrote:
> > 
> > Kris,
> > 
> > Did download the artifacts (drools-5.1.0.SNAPSHOT-bin.zip)
> > from the above location but ran into the same issue reported
> earlier.
> > 
> >
> /*------------------------------------------------------------------*/
> > 
> > java.lang.RuntimeException: Unable to load session snapshot
> > 	at
> >
>
org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:112)
> > 	at
> >
>
org.drools.persistence.session.JPASessionMarshallingHelper.<init>(JPASessionMarshallingHelper.java:46)
> > 	at
> >
>
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:194)
> > 	at
> >
>
org.drools.persistence.jpa.impl.JPAKnowledgeServiceProviderImpl.loadStatefulKnowledgeSession(JPAKnowledgeServiceProviderImpl.java:75)
> > 	at
> >
>
org.drools.persistence.jpa.JPAKnowledgeService.loadStatefulKnowledgeSession(JPAKnowledgeService.java:102)
> > 	at
> >
>
org.drools.examples.process.order.OrderExample.createWorkingMemory(OrderExample.java:279)
> > 	at
> >
>
org.drools.examples.process.order.OrderExample.<init>(OrderExample.java:107)
> > 	at
> >
> org.drools.examples.process.order.OrderExample.main(OrderExample.java:88)
> > Caused by: java.lang.NullPointerException
> > 	at
> >
>
org.drools.marshalling.impl.InputMarshaller.readLeftTuple(InputMarshaller.java:496)
> > 	at
> >
>
org.drools.marshalling.impl.InputMarshaller.readLeftTuples(InputMarshaller.java:426)
> > 	at
> >
>
org.drools.marshalling.impl.InputMarshaller.readFactHandles(InputMarshaller.java:349)
> > 	at
> >
>
org.drools.marshalling.impl.InputMarshaller.readSession(InputMarshaller.java:207)
> > 	at
> >
>
org.drools.marshalling.impl.DefaultMarshaller.unmarshall(DefaultMarshaller.java:75)
> > 	at
> >
>
org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:104)
> > 
> >
> /*------------------------------------------------------------------*/
> > 
> > 
> > I am  creating a JPA session and starting a process
> > with a human task and then stopping the engine without completing
> > the human task .Then trying to load from the earlier session.
> > 
> > Am I missing any calls before exit.
> > 
> > Appreciate your help,thanks in advance
> > 
> > Sanjay
> > 
> > 
> > Kris Verlaenen wrote:
> >> 
> >> We're planning to do a M1 near the end of the month, and a final a
> few
> >> weeks later.
> >> 
> >> Kris
> >> 
> >> Quoting SBalakrishnan <Sanjay.Balakrishnan at fnis.com>:
> >> 
> >>> 
> >>> Thanks Kris 
> >>> 
> >>> Will download from the below link and check.
> >>> 
> >>> Quick question, do you know when the official 5.1 release will
> be
> >>> available
> >>> ?
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> Kris Verlaenen wrote:
> >>> > 
> >>> > The fix for this issue has been added to trunk about a month
> ago
> >>> already
> >>> > I think, have you already tried with the 5.1.0 SNAPSHOT
> release?
> >>> Does
> >>> > this solve your issue?
> >>> > 
> >>> > You can get the snapshot at
> >>> >
> >>>
> https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/
> >>> > 
> >>> > Kris
> >>> > 
> >>> > Quoting SBalakrishnan <Sanjay.Balakrishnan at fnis.com>:
> >>> > 
> >>> >> 
> >>> >> Looks like I am running into the same/similar issue while
> >>> recreating
> >>> >> from a
> >>> >> session_id.
> >>> >> Exception pasted below.
> >>> >> 
> >>> >> Any idea whether it will be addressed in the coming release ?
> >>> >> 
> >>> >> 
> >>> >> Thanks in advance..
> >>> >> 
> >>> >> 
> >>> >> /*--------------------------------------------*/
> >>> >> 
> >>> >> Hibernate: select sessioninf0_.id as id0_0_,
> sessioninf0_.dirty
> >>> as
> >>> >> dirty0_0_, sessioninf0_.lastModificationDate as
> lastModi3_0_0_,
> >>> >> sessioninf0_.rulesByteArray as rulesByt4_0_0_,
> >>> sessioninf0_.startDate
> >>> >> as
> >>> >> startDate0_0_ from SessionInfo sessioninf0_ where
> >>> sessioninf0_.id=?
> >>> >> java.lang.RuntimeException: Unable to load session snapshot
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:112)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.persistence.session.JPASessionMarshallingHelper.<init>(JPASessionMarshallingHelper.java:46)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:171)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.persistence.jpa.impl.JPAKnowledgeServiceProviderImpl.loadStatefulKnowledgeSession(JPAKnowledgeServiceProviderImpl.java:75)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.persistence.jpa.JPAKnowledgeService.loadStatefulKnowledgeSession(JPAKnowledgeService.java:102)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.examples.process.order.OrderExample.createWorkingMemory(OrderExample.java:257)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.examples.process.order.OrderExample.<init>(OrderExample.java:99)
> >>> >> 	at
> >>> >>
> >>>
> org.drools.examples.process.order.OrderExample.main(OrderExample.java:80)
> >>> >> Caused by: java.lang.NullPointerException
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.marshalling.impl.InputMarshaller.readLeftTuple(InputMarshaller.java:496)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.marshalling.impl.InputMarshaller.readLeftTuples(InputMarshaller.java:426)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.marshalling.impl.InputMarshaller.readFactHandles(InputMarshaller.java:349)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.marshalling.impl.InputMarshaller.readSession(InputMarshaller.java:207)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.marshalling.impl.DefaultMarshaller.unmarshall(DefaultMarshaller.java:75)
> >>> >> 	at
> >>> >>
> >>> >
> >>>
> >>
>
org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:104)
> >>> >> /*--------------------------------------------*/
> >>> >> 
> >>> >> 
> >>> >> Mauricio Salatino wrote:
> >>> >> > 
> >>> >> > Ok, I will try to take a look at it.. this week..
> >>> >> > I will let you know if I can fix it
> >>> >> > 
> >>> >> > 2009/7/28 DroolsUser <rafiuddin.mk at gmail.com>:
> >>> >> >> Mark / salaboy, I am also facing same problem while
> recreate
> >>> the
> >>> >> session
> >>> >> >> from database. Can you advice any alternative, so that I
> can
> >>> go
> >>> >> forward
> >>> >> >> till
> >>> >> >> the next release. Moreover when is the new release is
> .......
> >>> Do
> >>> >> new
> >>> >> >> release
> >>> >> >> will targeting this kind problem? Please suggest any
> >>> alternative
> >>> >> to
> >>> >> >> recreate
> >>> >> >> the session from db. Thanks in advance......
> >>> >> >>
> >>> >> >> gairey wrote:
> >>> >> >> Mark, Done: https://jira.jboss.org/jira/browse/JBRULES-2199
> -
> >>> >> thanks for
> >>> >> >> the
> >>> >> >> quick response. Regards, Alan Mark Proctor Sent by:
> >>> >> >> rules-users-bounces at lists.jboss.org 08/07/2009 13:49
> Please
> >>> >> respond to
> >>> >> >> Rules
> >>> >> >> Users List To Rules Users List cc Subject Re:
> [rules-users]
> >>> >> Problem with
> >>> >> >> JPA
> >>> >> >> session persistence in Drools Flow (5.0.1) Can you open a
> JIRA
> >>> for
> >>> >> this,
> >>> >> >> and
> >>> >> >> we'll make sure it's done in the next few weeks:
> >>> >> >> https://jira.jboss.org/jira/browse/JBRULES thanks Mark
> >>> >> >> Alan.Gairey at tessella.com wrote: I'm currently using Drools
> >>> Flow
> >>> >> with JPA
> >>> >> >> session persistence enabled as described in section 5.1 of
> the
> >>> >> User
> >>> >> >> Guide.
> >>> >> >> As a process executes, session information is saved to the
> H2
> >>> >> database
> >>> >> >> correctly. The problem comes if a process only executes
> part
> >>> way
> >>> >> through,
> >>> >> >> and I then try to finish the process by recreating a
> session
> >>> using
> >>> >> the
> >>> >> >> code:
> >>> >> >> // recreate the session from database using the sessionId
> >>> ksession
> >>> >> =
> >>> >> >> JPAKnowledgeService.loadStatefulKnowledgeSession(
> sessionId,
> >>> >> kbase, null,
> >>> >> >> env ); This gives me a NullPointerException. Having looked
> >>> into
> >>> >> the
> >>> >> >> Drools
> >>> >> >> Flow source code, I think the problem is in the class
> >>> >> >>
> >>> >>
> >>> >
> >>>
> >>
>
drools-persistence-jpa\src\main\java\org\drools\persistence\session\SingleSessionCommandService.java.
> >>> >> >> The 4th constructor of this class is called as part of the
> >>> loading
> >>> >> of a
> >>> >> >> knowledge session from the H2 database; this in turn leads
> to
> >>> the
> >>> >> >> afterCompletion method of the inner class
> SynchronizationImpl
> >>> >> being
> >>> >> >> called.
> >>> >> >> The final two lines of this method are:
> >>> >> ((JPAProcessInstanceManager)
> >>> >> >> ((ReteooWorkingMemory)
> >>> >> >>
> session).getProcessInstanceManager()).clearProcessInstances();
> >>> >> >> ((JPAWorkItemManager) ((ReteooWorkingMemory)
> >>> >> >> session).getWorkItemManager()).clearWorkItems(); However,
> when
> >>> >> called via
> >>> >> >> the route described above, the session member variable of
> >>> >> >> SingleSessionCommandService has not been set, thus causing
> the
> >>> >> >> NullPointerException. (Interestingly, running the unit
> tests
> >>> for
> >>> >> >> drools-persistence-jpa does result in the
> NullPointerException
> >>> >> being
> >>> >> >> thrown
> >>> >> >> multiple times, although the tests are still listed as
> having
> >>> >> passed.) I
> >>> >> >> believe enclosing the above two lines as follows will fix
> the
> >>> >> problem: if
> >>> >> >> (session != null) { ((JPAProcessInstanceManager)
> >>> >> ((ReteooWorkingMemory)
> >>> >> >>
> session).getProcessInstanceManager()).clearProcessInstances();
> >>> >> >> ((JPAWorkItemManager) ((ReteooWorkingMemory)
> >>> >> >> session).getWorkItemManager()).clearWorkItems(); } Also,
> in
> >>> the
> >>> >> 4th
> >>> >> >> constructor of SingleSessionCommandService, after the
> session
> >>> has
> >>> >> been
> >>> >> >> set,
> >>> >> >> the following line needs to be added to ensure the session
> id
> >>> is
> >>> >> the same
> >>> >> >> as
> >>> >> >> the session info id: ((ReteooStatefulSession)
> >>> >> this.session).setId(
> >>> >> >> this.sessionInfo.getId() ); (This line is present at the
> end
> >>> of
> >>> >> the 3rd
> >>> >> >> constructor.) It would be great if this fix could make it
> into
> >>> the
> >>> >> Drools
> >>> >> >> 5.1 release. Thanks.
> >>> >> _______________________________________________
> >>> >> >> rules-users mailing list rules-users at lists.jboss.org
> >>> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>> >> >> _______________________________________________
> rules-users
> >>> >> mailing list
> >>> >> >> rules-users at lists.jboss.org
> >>> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>> >> >> _______________________________________________
> rules-users
> >>> >> mailing list
> >>> >> >> rules-users at lists.jboss.org
> >>> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>> >> >>
> >>> >> >> ________________________________
> >>> >> >> View this message in context: Re: Problem with JPA session
> >>> >> persistence in
> >>> >> >> Drools Flow (5.0.1)
> >>> >> >> Sent from the drools - user mailing list archive at
> >>> Nabble.com.
> >>> >> >>
> >>> >> >> _______________________________________________
> >>> >> >> rules-users mailing list
> >>> >> >> rules-users at lists.jboss.org
> >>> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>> >> >>
> >>> >> >>
> >>> >> > 
> >>> >> > 
> >>> >> > 
> >>> >> > -- 
> >>> >> >  - http://salaboy.wordpress.com
> >>> >> >  - http://www.jbug.com.ar
> >>> >> >  - Salatino "Salaboy" Mauricio -
> >>> >> > _______________________________________________
> >>> >> > rules-users mailing list
> >>> >> > rules-users at lists.jboss.org
> >>> >> > https://lists.jboss.org/mailman/listinfo/rules-users
> >>> >> > 
> >>> >> > 
> >>> >> 
> >>> >> -- 
> >>> >> View this message in context:
> >>> >>
> >>> >
> >>>
> >>
>
http://www.nabble.com/Problem-with-JPA-session-persistence-in-Drools-Flow-%285.0.1%29-tp24377236p24909794.html
> >>> >> Sent from the drools - user mailing list archive at
> Nabble.com.
> >>> >> 
> >>> >> _______________________________________________
> >>> >> 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
> >>> > _______________________________________________
> >>> > rules-users mailing list
> >>> > rules-users at lists.jboss.org
> >>> > https://lists.jboss.org/mailman/listinfo/rules-users
> >>> > 
> >>> > 
> >>> 
> >>> -- 
> >>> View this message in context:
> >>>
> >>
>
http://www.nabble.com/Problem-with-JPA-session-persistence-in-Drools-Flow-%285.0.1%29-tp24377236p24957542.html
> >>> Sent from the drools - user mailing list archive at Nabble.com.
> >>> 
> >>> _______________________________________________
> >>> 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
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users at lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >> 
> >> 
> > 
> > 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/Problem-with-JPA-session-persistence-in-Drools-Flow-%285.0.1%29-tp24377236p25287940.html
> Sent from the drools - user mailing list archive at Nabble.com.
> 
> _______________________________________________
> 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