<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Esteban, I have created a ticket for
      this with<br>
      an explanation of the weird behavior.<br>
      <br>
      <a class="moz-txt-link-freetext" href="https://issues.jboss.org/browse/DROOLS-414">https://issues.jboss.org/browse/DROOLS-414</a><br>
      <br>
      The problem is in QueryElementBuilder line#343.<br>
      It's an easy fix but I don't have time for it right now, <br>
      could someone look into it?<br>
      <br>
      Thanks<br>
      Davide<br>
      <br>
      <br>
      On 01/22/2014 06:00 PM, Esteban Aliverti wrote:<br>
    </div>
    <blockquote
cite="mid:CAKsR9Q8=vvYShTOWO98yiUX-d02EiYkToZpyLgQU5oDTp6yhPw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Good catch Davide. I can confirm that not using
        nested accessors the query works as expected.
        <div><br>
        </div>
        <div>Regards,</div>
      </div>
      <div class="gmail_extra"><br clear="all">
        <div><br>
          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
          <br>
          Esteban Aliverti<br>
          - Blog @ <a moz-do-not-send="true"
            href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a></div>
        <br>
        <br>
        <div class="gmail_quote">On Wed, Jan 22, 2014 at 6:57 PM, Davide
          Sottara <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:dsotty@gmail.com" target="_blank">dsotty@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000">
              <div>Indeed, the use case can be simplified further:<br>
                <br>
                <tt>package org.drools.test.bc;</tt><tt><br>
                </tt><tt><br>
                </tt><tt>declare Parent</tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; attribute2 : String</tt><tt><br>
                </tt><tt>end</tt><tt><br>
                </tt><tt><br>
                </tt><tt>declare Child</tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; parentId : String</tt><tt><br>
                </tt><tt>end</tt><tt><br>
                </tt><tt><br>
                </tt><tt>query getChildWithName( String $parentId, Child
                  $child )</tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; $child:= Child( parentId == $parentId )</tt>
                <div class="im"><tt><br>
                  </tt><tt>end</tt><tt><br>
                  </tt><tt><br>
                  </tt><tt>rule "Insert Children"</tt><tt><br>
                  </tt><tt>when</tt><tt><br>
                  </tt></div>
                <tt>then</tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; Parent p1 = new Parent( "a1" );</tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; Child c1p1 = new Child( "1" );</tt><tt><br>
                </tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; insert( c1p1 );</tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; insert( p1 );</tt>
                <div class="im"><tt><br>
                  </tt><tt>end</tt><tt><br>
                  </tt><tt><br>
                  </tt><tt>rule "Rule A"</tt><tt><br>
                  </tt><tt>when</tt><tt><br>
                  </tt></div>
                <tt>&nbsp;&nbsp;&nbsp; $p: Parent( $a2 : attribute2 )</tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; ?getChildWithName( $p.attribute2, $child;)</tt><tt><br>
                </tt><tt>then</tt><tt><br>
                </tt><tt>&nbsp;&nbsp;&nbsp; System.out.println("FOUND: "+ $child + "
                  &gt;&gt; " + $child.getParentId() + " == " +
                  $p.getAttribute2() + " ??" );</tt><tt><br>
                </tt><tt>end</tt><tt><br>
                </tt><tt><br>
                </tt>It has nothing to do with nested objects, @PR or
                modifications. <br>
                It seems that the culprit is the chained property
                accessor.
                <div class="im"><br>
                  <br>
                  Davide<br>
                  <br>
                  <br>
                  <br>
                  On 01/22/2014 02:22 PM, Esteban Aliverti wrote:<br>
                </div>
              </div>
              <blockquote type="cite">
                <div>
                  <div class="h5">
                    <div dir="ltr">Hi guys,
                      <div>I was writing some rules using backward
                        chaining and found a strange behavior.&nbsp;</div>
                      <div>I managed to isolate the error in the test
                        project I'm attaching.&nbsp;</div>
                      <div><br>
                      </div>
                      <div>In the project I have 2 classes: Parent and
                        Child</div>
                      <div><br>
                      </div>
                      <div>Parent:</div>
                      <div>&nbsp; &nbsp; * String id</div>
                      <div>&nbsp; &nbsp; * String attribute1</div>
                      <div>&nbsp; &nbsp; * String attribute2</div>
                      <div>&nbsp; &nbsp; * List&lt;Child&gt; children</div>
                      <div><br>
                      </div>
                      <div>Child:</div>
                      <div>&nbsp; &nbsp; * String parentId;</div>
                      <div>&nbsp; &nbsp; * String name;</div>
                      <div>&nbsp; &nbsp; * String value;</div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                      <div>In the test I'm creating 1 Parent object with
                        just 1 child and then inserting the Parent
                        object into a drools session:</div>
                      <div><br>
                      </div>
                      <div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; Parent p1 = new Parent();</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; p1.setId("1");</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; p1.setAttribute1("a1");</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; p1.setAttribute2(null);</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>
                        <div> &nbsp; &nbsp; &nbsp; &nbsp; Child c1p1 = new Child();</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; c1p1.setName("n1");</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; c1p1.setParentId(p1.getId());</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; c1p1.setValue("v1.1");</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; p1.addChild(c1p1);</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; kSession.insert(p1);</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; kSession.fireAllRules();</div>
                      </div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                      <div>So far so good.&nbsp;</div>
                      <div>The rules I have in my session are the
                        following:</div>
                      <div><br>
                      </div>
                      <div>
                        <div>declare Parent</div>
                        <div>&nbsp; &nbsp; @propertyReactive</div>
                        <div>end</div>
                        <div><br>
                        </div>
                        <div>query getChildWithName(String $parentId,
                          String $name, Child $child)</div>
                        <div>&nbsp; &nbsp; $child:= Child(parentId == $parentId,
                          name == $name)</div>
                        <div>end</div>
                        <div><br>
                        </div>
                        <div>rule "Insert Children"</div>
                        <div>when</div>
                        <div>&nbsp; &nbsp; $p: Parent() &nbsp; &nbsp;@watch(!*)</div>
                        <div>&nbsp; &nbsp; $c: Child() from $p.children</div>
                        <div>then</div>
                        <div>&nbsp; &nbsp; System.out.println("Inserting child
                          "+$c);</div>
                        <div>&nbsp; &nbsp; insert($c);</div>
                        <div>end</div>
                        <div><br>
                        </div>
                        <div>rule "Rule A"</div>
                        <div>when</div>
                        <div>&nbsp; &nbsp; $p: Parent(attribute2 != null)</div>
                        <div>&nbsp; &nbsp; ?getChildWithName($p.attribute2, "n1",
                          $child;)</div>
                        <div>then</div>
                        <div>&nbsp; &nbsp; System.out.println("FOUND: "+$child+".
                          The attribute 'parentId' of this object must
                          have the value '"+$p.getAttribute2()+"'. Does
                          it? "+$child.getParentId()+" ==
                          "+$p.getAttribute2()+" ??");</div>
                        <div>&nbsp; &nbsp; globalList.add($child);</div>
                        <div>end</div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                        <div>rule "Copy Attribute1 into Attribute2"</div>
                        <div>when</div>
                        <div>&nbsp; &nbsp; $p: Parent(attribute1 != null,
                          attribute2 == null)</div>
                        <div>then</div>
                        <div>&nbsp; &nbsp; modify($p){</div>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; setAttribute2($p.getAttribute1())</div>
                        <div>&nbsp; &nbsp; }</div>
                        <div>end</div>
                      </div>
                      <div><br>
                      </div>
                      <div>The important part here is 'Rule A' and 'Copy
                        Attribute1 into Attribute2'. The latter copies
                        the value of attribute1 to attribute2 for any
                        Parent object present in the session. (Note that
                        the parent I'm inserting has attribute2 = null).
                        'Rule A' is then using a query to get a Child
                        object that has a parent with id = $p.attribute2
                        (where $p is a previously matched Parent).</div>
                      <div>Given that I only have 1 Parent in my session
                        and that its id is '1' I don't expect 'Rule A'
                        to be activated/executed. When I modify
                        parent.attribute2 in 'Copy Attribute1 into
                        Attribute2' I'm setting its value to 'a1'. 'Rule
                        A' (via the query) should then look for a Child
                        with parentid = 'a1' and It shouldn't find
                        anything.&nbsp;</div>
                      <div>Funny thing is that 'Rule A' activates and
                        fires. The child object that is 'returned' by
                        the query has a parentId of '1' so I don't know
                        how this behavior is possible. If you take a
                        look at the System.out output you will see that
                        the activation makes no sense at all.</div>
                      <div><br>
                      </div>
                      <div>Am I doing something wrong in my project? Is
                        this a bug? Is this the expected behavior?</div>
                      <div><br>
                      </div>
                      <div>Regards,</div>
                      <div><br>
                      </div>
                      <div><br clear="all">
                        <div><br>
                          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
                          <br>
                          Esteban Aliverti<br>
                          - Blog @ <a moz-do-not-send="true"
                            href="http://ilesteban.wordpress.com"
                            target="_blank">http://ilesteban.wordpress.com</a></div>
                      </div>
                    </div>
                    <br>
                    <fieldset></fieldset>
                    <br>
                  </div>
                </div>
                <div class="im">
                  <pre>_______________________________________________
rules-users mailing list
<a moz-do-not-send="true" href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a moz-do-not-send="true" href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
                </div>
              </blockquote>
              <br>
            </div>
            <br>
            _______________________________________________<br>
            rules-users mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
            <a moz-do-not-send="true"
              href="https://lists.jboss.org/mailman/listinfo/rules-users"
              target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
    </blockquote>
    <br>
  </body>
</html>