In fact in your case you when condition doesn’t make any sense – B will never equal the empty string as B isn’t a string.

You probable want the following:

rule “foo”

when
   $a :A(Type == "Prod" , objectB == null)
then
   B bobject = new B();

   bobject.setType(“Prod”);

   bobject.setId($a.getNumber().getId());

   modify($a) {

      setObjectB(bobject);

    };

end

 

This rule only executes when objectB  is null, this means you won’t get into the loop as once you have created objectB  the rule won’t evaluate to true again.

 

Thomas



From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Esteban Aliverti
Sent: 03 June 2010 23:43
To: Rules Users List
Subject: Re: [rules-users] Object Referencing Error

 

Yes, your rule entered in an infinite loop because when every time you insert/modify/retract a Fact, rules are reevaluated to check if the insertion/modification/retraction generates activations or not. In your case, your rule is being reevaluated every time you update your $a object, the evaluation ends firing the rule, and this starts an endless loop. 

If you only have this behavior with this rule, you can consider using the "no-loop" attribute. If your problem is multiple rules being re executed (and you don't wont that) you can use "lock-on-active" attribute. Try to read the documentation about these attributes for further information. 

It is very important for the people new in drools to understand the life cycle of a rule.

 

Best,  

On Thu, Jun 3, 2010 at 7:33 PM, Fnu Mahalakshmi <FMahalakshmi@nyx.com> wrote:

Hi,

I tried what you said but program goes into an infinite loop.
It does not break out of the when loop only.
I did exactly as you mentioned.
In the test information I put in a.type = "Prod"
And a.bObject(new B());
Any idea whats wrong??

Thanks,
M

-----Original Message-----
From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of rules-users-request@lists.jboss.org
Sent: Thursday, June 03, 2010 4:52 PM
To: rules-users@lists.jboss.org
Subject: rules-users Digest, Vol 43, Issue 15

Send rules-users mailing list submissions to
       rules-users@lists.jboss.org

To subscribe or unsubscribe via the World Wide Web, visit
       https://lists.jboss.org/mailman/listinfo/rules-users
or, via email, send a message with subject or body 'help' to
       rules-users-request@lists.jboss.org

You can reach the person managing the list at
       rules-users-owner@lists.jboss.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of rules-users digest..."


Today's Topics:

  1. Re: Object Referencing error: (Esteban Aliverti)


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

Message: 1
Date: Thu, 3 Jun 2010 17:51:10 -0300
From: Esteban Aliverti <esteban.aliverti@gmail.com>
Subject: Re: [rules-users] Object Referencing error:
To: Rules Users List <rules-users@lists.jboss.org>
Message-ID:
       <AANLkTimeZIJ5VfMTBESLFJIWoc_4MEZSXbKMIXAvJRiC@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

You can't modify bobject, becuase it doesn't exist inside the session. You
just created it a few lines above. Maybe you need an insert() or maybe you
need the bobject reference from the LHS. Something like this:

*rule* "prod"



     *when*

        $a :A(Type == "Prod" , objectB != "")

     *then*

  B bobject = *new* B();

        $a.getObjectB().setType( "Prod" );

        $a.getObjectB().setId($a.getNumber().getId());

        *update*($a);

*      end*

Note that you need to update $a and not B, because A is the inserted Fact in
your session.

Best,


2010/6/3 Fnu Mahalakshmi <FMahalakshmi@nyx.com>

>  Hi,
>
>
>
> I am getting the following error when I try to do complex object
> referencing in drools:
>
> My class:
>
> A{
>
> String Type;
>
> B objectb;
>
> //getters and setters for above
>
> }
>
>
>
> My rules:
>
>
>
> *rule* "prod"
>
>
>
>       *when*
>
>      $a :A(Type == "Prod" , objectB != "")
>
>       *then*
>
> B bobject = *new* B();
>
>      bobject.setType( "Prod" );
>
>      bobject.setId($a.getNumber().getId());
>
>      *update*(bobject);
>
>
>
> *end*
>
> * *
>
> *I want to basically output a file which has updated values of B (type,
> Id)
>
> *
>
> * *
>
> *Error:*
>
> *org.drools.spi.ConsequenceException*: *org.drools.FactException*: Update
> error: handle not found for object: com.org.Ip@f42ad0. Is it in the
> working memory?
>
>       at
> org.drools.base.DefaultConsequenceExceptionHandler.handleException(*
> DefaultConsequenceExceptionHandler.java:13*)
>
>       at org.drools.common.DefaultAgenda.fireActivation(*
> DefaultAgenda.java:558*)
>
>       at org.drools.common.DefaultAgenda.fireNextItem(*
> DefaultAgenda.java:518*)
>
>       at org.drools.common.AbstractWorkingMemory.fireAllRules(*
> AbstractWorkingMemory.java:475*)
>
>       at org.drools.common.AbstractWorkingMemory.fireAllRules(*
> AbstractWorkingMemory.java:439*)
>
>       at com.org.DroolsTest.main(*DroolsTest.java:30*)
>
> Caused by: *org.drools.FactException*: Update error: handle not found for
> object: com.org.Ip@f42ad0. Is it in the working memory?
>
>       at org.drools.base.DefaultKnowledgeHelper.update(*
> DefaultKnowledgeHelper.java:100*)
>
>       at com.org.Rule_Prod_Ip_0.consequence(*Rule_Prod_Ip_0.java:10*)
>
>       at com.org.Rule_Prod_Ip_0ConsequenceInvoker.evaluate(*
> Rule_Prod_Ip_0ConsequenceInvoker.java:22*)
>
>       at org.drools.common.DefaultAgenda.fireActivation(*
> DefaultAgenda.java:554*)
>
>       ... 4 more
>
>
>
> Please help! I am very new to drools! Not able to figure out why this
> error:
>
>
>
> I am using eclipse and working on Windows machine. Error above was
> generated on eclipse console.
>
>
>
> Thank you.
>
>
>
> M
>
> ------------------------------
>
> *Please consider the environment before printing this email.*
>
> *Visit our website at http://www.nyse.com
> *****************************************************************************
>
> Note: The information contained in this message and any attachment to it is
> privileged, confidential and protected from disclosure. If the reader of
> this message is not the intended recipient, or an employee or agent
> responsible for delivering this message to the intended recipient, you are
> hereby notified that any dissemination, distribution or copying of this
> communication is strictly prohibited. If you have received this
> communication in error, please notify the sender immediately by replying to
> the message, and please delete it from your system. Thank you. NYSE
> Euronext. *
>
>
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100603/f0f29ddf/attachment.html

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

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


End of rules-users Digest, Vol 43, Issue 15
*******************************************
Please consider the environment before printing this email.

Visit our website at http://www.nyse.com

****************************************************

Note:  The information contained in this message and any attachment to it is privileged, confidential and protected from disclosure.  If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.  If you have received this communication in error, please notify the sender immediately by replying to the message, and please delete it from your system.  Thank you.  NYSE Euronext.


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




--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti




**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************