[rules-users] Collect and hibernate

richarda richard.ambridge at gmail.com
Thu Oct 29 11:40:07 EDT 2009


Ok,  I have found if I run in:
        conf.setOption( EventProcessingOption.CLOUD );
it works..

but in 
        conf.setOption( EventProcessingOption.STREAM );

i get Null for the object

any idea why?



richarda wrote:
> 
> Thanks for the continued help... but
> 
> ---
> ArrayList<MessageAsEvent> a=new ArrayList<MessageAsEvent>();
> MessageAsEvent a1=new MessageAsEvent(); a1.setSerial("serial123");
> a1.setUuid("mesC:7"); a1.setId(888); a.add(a1);
> MessageAsEvent a2=new MessageAsEvent(); a2.setSerial("serial123");
> a2.setUuid("mesC:7"); a2.setId(889);a.add(a2);
> 
> ksession.setGlobal("hibernateSession", hibernateSession);
> ksession.setGlobal("data", a);
> 
> ----
> 
> global java.util.ArrayList data;
> 
> rule "Repeating as signature"
> 	when
> 		 $m : MessageAsEvent(uuid=="mesC:7")
> 		 $others :  MessageAsEvent(uuid=="mesC:7", id!=$m.id) 
> 		                           from data  		 	                    
> 	then 
> 		System.out.println("++++++++++++Gathering in signatures m="+$m+"
> data="+$others);	
> 	    insert($others);		
> end
> 
> ----
> 
> and I still get;
> Audit:-
> 
> <org.drools.audit.event.ActivationLogEvent>
>   <type>4</type>
>   <activationId>Repeating as signature [15, 14]</activationId>
>   <rule>Repeating as signature</rule>
>   <declarations>$others=MessageAsEvent:[888] uuid=mesC:7 serial=serial123
> count=0(15); $m=MessageAsEvent:[254] uuid=mesC:7 serial=serial123
> count=7(14)</declarations>
>   <ruleFlowGroup>Signature</ruleFlowGroup>
> </org.drools.audit.event.ActivationLogEvent>
> <org.drools.audit.event.ActivationLogEvent>
>   <type>4</type>
>   <activationId>Repeating as signature [16, 14]</activationId>
>   <rule>Repeating as signature</rule>
>   <declarations>$others=MessageAsEvent:[889] uuid=mesC:7 serial=serial123
> count=0(16); $m=MessageAsEvent:[254] uuid=mesC:7 serial=serial123
> count=7(14)</declarations>
>   <ruleFlowGroup>Signature</ruleFlowGroup>
> </org.drools.audit.event.ActivationLogEvent>
> 
> Console:-
> ++++++++++++Gathering in signatures m=MessageAsEvent:[254] uuid=mesC:7
> serial=serial123 count=7 data=null
> ++++++++++++Gathering in signatures m=MessageAsEvent:[254] uuid=mesC:7
> serial=serial123 count=7 data=null
> 
> with data=null  being shown
> 
> 
> 
> Edson Tirelli-4 wrote:
>> 
>>    You must be having a problem with the hibernate query then. Just as a
>> test, try replacing the query call with an arbitrary method call that
>> returns a couple objects.
>> 
>>    Edson
>> 
>> 
>> 
>> 2009/10/29 richarda <richard.ambridge at gmail.com>
>> 
>>>
>>> Using Drools 5.0.1
>>>
>>> I get the same results with the below rule.
>>> I leave the System.out.println in,  and the rule executes the number of
>>> times for the number of items that should be loaded from the hibernate,
>>> but each time the $o is still null.
>>>
>>> the insert seems to be ignored, audit shows no record of it,  but I
>>> assume
>>> insert(null)  is ignored by drools
>>>
>>>
>>> Edson Tirelli-4 wrote:
>>> >
>>> >     Did you tried this?
>>> >
>>> >        when
>>> >                 $m : MessageAsEvent(uuid=="mesC:7")
>>> >                 $o :  MessageAsEvent(uuid=="mesC:7", id!=$m.id) from
>>> > hibernateSession.createQuery("from MessageAsEvent where
>>> > serial=?").setParameter(0,$m.serial).list()
>>> >        then
>>> >                 insert($o)
>>> >        end
>>> >
>>> >     In any case, collect should work too. Which version of drools are
>>> you
>>> > using?
>>> >
>>> >     []s
>>> >     Edson
>>> >
>>> > 2009/10/29 richarda <richard.ambridge at gmail.com>
>>> >
>>> >>
>>> >> Hi again,
>>> >>
>>> >> I wish to have a rule that when an Event has a certain uuid then load
>>> >> into
>>> >> working memory all other events that have been received for this
>>> unit...
>>> >>
>>> >> So I write the rule:
>>> >>
>>> >> rule "Repeating"
>>> >>
>>> >>        when
>>> >>                 $m : MessageAsEvent(uuid=="mesC:7")
>>> >>                 $others : LinkedList() from collect (
>>> >>                           MessageAsEvent(uuid=="mesC:7", id!=$m.id)
>>> >>                               from hibernateSession.createQuery("from
>>> >> MessageAsEvent where
>>> >> serial=?").setParameter(0,$m.serial).list()
>>> >>                        )
>>> >>        then
>>> >>                System.out.println("Gathering m="+$m+"
>>> data="+$others);
>>> >> end
>>> >>
>>> >>
>>> >> Audit log shows: (wish cut and paste would work from Eclipse audit
>>> view)
>>> >>
>>> >>  <activationId>Repeating [131, 14]</activationId>
>>> >>  <rule>Repeating FAN</rule>
>>> >>  <declarations>$others=[MessageAsEvent:[124] uuid=mesC:7
>>> serial=serial123
>>> >> count=7, MessageAsEvent:[94] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[64] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[118] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[112] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[106] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[100] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[88] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[82] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[76] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[70] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[58] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[52] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[46] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[40] uuid=mesC:7 serial=serial123 count=7,
>>> >> MessageAsEvent:[34] uuid=mesC:7 serial=serial123 count=7](131);
>>> >> $m=MessageAsEvent:[130] uuid=mesC:7 serial=serial123
>>> >> count=7(14)</declarations>
>>> >>  <ruleFlowGroup>Gathering</ruleFlowGroup>
>>> >>
>>> >>
>>> >>
>>> >> So, you can see that the rule fired with $others having all the data,
>>> >> and
>>> >> $m being the main uuid
>>> >>
>>> >>
>>> >> but the output of the rule is:
>>> >> Gathering m=MessageAsEvent:[130] uuid=mesC:7 serial=serial123 count=7
>>> >> data=null
>>> >>
>>> >> so, the $others has been translated to a null.
>>> >>
>>> >> I'm trying to copy the Expert example:
>>> >>
>>> >> import java.util.LinkedList;
>>> >>
>>> >> rule "Send a message to all mothers"
>>> >> when
>>> >>    $town : Town( name == 'Paris' )
>>> >>    $mothers : LinkedList()
>>> >>               from collect( Person( gender == 'F', children > 0 )
>>> >>                             from $town.getPeople()
>>> >>                           )
>>> >> then
>>> >>    # send a message to all mothers
>>> >> end
>>> >>
>>> >> which indicates that $mothers will be available in the RHS
>>> >>
>>> >> for reference, the audit log shows when the rule fires:
>>> >>
>>> >>
>>> >> <org.drools.audit.event.ActivationLogEvent>
>>> >>  <type>6</type>
>>> >>  <activationId>Repeating [-1, 14]</activationId>
>>> >>  <rule>Repeating FAN</rule>
>>> >>  <declarations>$m=MessageAsEvent:[130] uuid=mesC:7 serial=serial123
>>> >> count=7(14)</declarations>
>>> >>  <ruleFlowGroup>Gathering</ruleFlowGroup>
>>> >>
>>> >>
>>> >> What am I doing wrong?
>>> >> I basically want all the MessageAsEvent added to working memory, so
>>> later
>>> >> other rules will do work on all the events.
>>> >>
>>> >> Cheers
>>> >> Ric
>>> >>
>>> >> --
>>> >> View this message in context:
>>> >> http://www.nabble.com/Collect-and-hibernate-tp26112042p26112042.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
>>> >>
>>> >
>>> >
>>> >
>>> > --
>>> >  Edson Tirelli
>>> >  JBoss Drools Core Development
>>> >  JBoss by Red Hat @ www.jboss.com
>>> >
>>> > _______________________________________________
>>> > 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/Collect-and-hibernate-tp26112042p26113182.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
>>>
>> 
>> 
>> 
>> -- 
>>  Edson Tirelli
>>  JBoss Drools Core Development
>>  JBoss by Red Hat @ www.jboss.com
>> 
>> _______________________________________________
>> 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/Collect-and-hibernate-tp26112042p26115484.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list