[rules-users] Collect and hibernate

richarda richard.ambridge at gmail.com
Thu Oct 29 09:36:46 EDT 2009


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.




More information about the rules-users mailing list