I agree - my mistake, Because of tests I've forgotten to delete 'X'... So it's not the case... Sorry...
But did another try and when I've used

rule "Check Object A and Set Default"
dialect "mvel"

It was not working correctly. Then I moved to:

rule "Check Object A and Set Default"
dialect "java"

and it works fine. So it is ok if we will change Mike's 'NOT WORKING' example to:

--------------------------------------------------
package com.sample

import com.sample.ObjectA
import org.drools.WorkingMemory

function void insertDefault(WorkingMemory workingMemory) {
  SomeDefault someDefault = new SomeDefault();
  someDefault.setMinValueA(100);
  someDefault.setMinValueB(20.0);
  someDefault.setMaxValueB(20000.0);
  workingMemory.insert(someDefault);
}

declare SomeDefault
  minValueA : Integer
  minValueB : Double
  maxValueB : Double
end

rule "Check Object A and Set Default"
  dialect "java"
  agenda-group "Foo"
  salience 100
  when
    $a : ObjectA()
  then
    insertDefault(drools.getWorkingMemory());
end

rule "Use the defaults"
  dialect "mvel"
  agenda-group "Foo"
  salience 90
  when
    $default : SomeDefault()
  then
    System.out.println("Default minA=" + $default.minValueA)
end
--------------------------------------------------

Any ideas why?

2011/12/30 Mauricio Salatino <salaboy@gmail.com>
One is SomeDefault and the other one is SomeDefaultX.
The Declared type, as far as I remember overrides the to string with
the representation that you are seeing there:
SomeDefault( minValueA=100, minValueB=20.0, maxValueB=20000.0 )
What is SomeDefaultX??
Cheers
2011/12/29 Maciej Gowin <maciej.abacus.gowin@gmail.com>:
> I did some debbuging with 'declare SomeDefault'. This is what I found:
>
> CASE1: RHS = drools.getWorkingMemory().insert(new SomeDefaultX())
> Working memory objects:
> Object[fact
> 0:2:2082419441:2082419441:2:DEFAULT:com.sample.SomeDefaultX@7c1f32f1]
> Object[fact 0:1:140683595:140683595:1:DEFAULT:com.sample.ObjectA@862a94b]
>
> CASE2: RHS = insertDefault(drools.getWorkingMemory())
> Working memory objects:
> Object[fact 0:2:176338845:1:2:DEFAULT:SomeDefault( minValueA=100,
> minValueB=20.0, maxValueB=20000.0 )]
> Object[fact 0:1:1125048577:1125048577:1:DEFAULT:com.sample.ObjectA@430ee101]
>
> Please note the difference between DEFAULT:com.sample.SomeDefault and
> DEFAULT:SomeDefault.
> So when inserting an object to WorkingMemory inside function insertDefault
> which is declared in DRL file
> something strange is going on... It seems like it is a bug. It is worth
> mentioning that I get following result
> inside insertDefault:
> System.out.println(SomeDefault.class.getName());
> ---> com.sample.SomeDefault
>
> Hope it will help :)
>
>
>
>
> 2011/12/30 Maciej Gowin <maciej.abacus.gowin@gmail.com>
>>
>> Of course it's only my guess. I'm not an expert. Please correct me if I'm
>> wrong :)
>>
>>
>> 2011/12/30 Maciej Gowin <maciej.abacus.gowin@gmail.com>
>>>
>>> It's not the different WorkingMemory. It's all about class name
>>> confusion. It looks like the class type does not match.
>>> Please try to create SomeDefault in standard way, not with 'declare'
>>> statement. It works ok.
>>>
>>>
>>> 2011/12/30 Mike Key <mikey@zenbitz.com>
>>>>
>>>> I guess that is exactly my confusion :)  Why would it be that doing the
>>>> exact same thing, one inserting into working memory from a function and the
>>>> other simply doing it within the RHS of the rule cause downstream rules not
>>>> to fire in the function call case?  The rules are both in the same
>>>> agenda-group, both the function example and the insert from the RHS of the
>>>> rule example are simply inserting a new fact into working memory.
>>>>
>>>> It makes it seem like the function call is somehow inserting into a
>>>> *different* working memory, which I'm sure is not the case, but the
>>>> downstream rule does not fire none-the-less.
>>>>
>>>> Thanks for any clarity.
>>>>
>>>>
>>>> On Thu, Dec 29, 2011 at 3:59 PM, Mauricio Salatino <salaboy@gmail.com>
>>>> wrote:
>>>>>
>>>>> Agenda-groups segment the agenda and not the working memory :)
>>>>> Probably that is part of your confusion.
>>>>>
>>>>>
>>>>> 2011/12/29 Mike Key <mikey@zenbitz.com>:
>>>>> > I am a fairly new Drools user and am trying to understand how working
>>>>> > memory
>>>>> > is segmented when using agenda groups.  I have an agenda-group that
>>>>> > has
>>>>> > focus set immediately from the session as follows with a few objects
>>>>> > being
>>>>> > inserted:
>>>>> >
>>>>> > ksession.insert(objectA);
>>>>> > ksession.insert(objectB);
>>>>> > ksession.getAgenda().getAgendaGroup("Foo").setFocus();
>>>>> >
>>>>> > I have 2 rules simplified down to illustrate my confusion.  The first
>>>>> > rule
>>>>> > simply sets some default values evaluated in the second rule if
>>>>> > objectA
>>>>> > exists.  In the example that works I set the defaults in the RHS
>>>>> > explicitly.
>>>>> >  However I want to use these defaults from different agenda-groups,
>>>>> > so when
>>>>> > I put them in a function, the second rule never fires, the activation
>>>>> > is
>>>>> > created for the first rule but never the second.  Can someone tell me
>>>>> > why
>>>>> > the use of a function seems to alter the truth of the rule?
>>>>> >
>>>>> > THIS WORKS:
>>>>> >
>>>>> > declare SomeDefault
>>>>> >   minValueA : Integer
>>>>> >   minValueB : Double
>>>>> >   maxValueB : Double
>>>>> > end
>>>>> >
>>>>> > rule "Check Object A and Set Default"
>>>>> >   agenda-group "Foo"
>>>>> >   salience 100
>>>>> >   when
>>>>> >     $a : ObjectA()
>>>>> >   then
>>>>> >     default = new SomeDefault()
>>>>> >     default.minValueA = 100
>>>>> >     default.minValueB = 20.0
>>>>> >     default.maxValueB = 20000.0
>>>>> >     insert(default)
>>>>> > end
>>>>> >
>>>>> > rule "Use the defaults"
>>>>> >   agenda-group "Foo"
>>>>> >   salience 100
>>>>> >   when
>>>>> >     $default : SomeDefault()
>>>>> >   then
>>>>> >     System.out.println("Default minA=" + $default.minValueA)
>>>>> > end
>>>>> >
>>>>> > THIS DOES NOT WORK:
>>>>> >
>>>>> > declare SomeDefault
>>>>> >   minValueA : Integer
>>>>> >   minValueB : Double
>>>>> >   maxValueB : Double
>>>>> > end
>>>>> >
>>>>> > rule "Check Object A and Set Default"
>>>>> >   agenda-group "Foo"
>>>>> >   salience 100
>>>>> >   when
>>>>> >     $a : ObjectA()
>>>>> >   then
>>>>> >     insertDefault(drools.getWorkingMemory())
>>>>> > end
>>>>> >
>>>>> > rule "Use the defaults"
>>>>> >   agenda-group "Foo"
>>>>> >   salience 90
>>>>> >   when
>>>>> >     $default : SomeDefault()
>>>>> >   then
>>>>> >     System.out.println("Default minA=" + $default.minValueA)
>>>>> > end
>>>>> >
>>>>> > function void insertDefault(WorkingMemory workingMemory) {
>>>>> >   SomeDefault default = new SomeDefault();
>>>>> >   default.setMinValueA(100);
>>>>> >   default.setMinValueB(20.0);
>>>>> >   default.setMaxValueB(20000.0);
>>>>> >   workingMemory.insert(default);
>>>>> > }
>>>>> >
>>>>> > In the latter (non-working) example the first rule activates and then
>>>>> > drools
>>>>> > returns, it never even attempts to try to fire the second rule.
>>>>> >  However in
>>>>> > the working example BOTH rules fire as I would expect.  I am guessing
>>>>> > this
>>>>> > is a simple misunderstanding on my part.  Any assistance in
>>>>> > understanding
>>>>> > why this nuance doesn't seem to work would be greatly appreciated.
>>>>> >
>>>>> > Thanks.
>>>>> >
>>>>> > MiKey
>>>>> >
>>>>> > _______________________________________________
>>>>> > rules-users mailing list
>>>>> > rules-users@lists.jboss.org
>>>>> > https://lists.jboss.org/mailman/listinfo/rules-users
>>>>> >
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>  - CTO @ http://www.plugtree.com
>>>>>  - MyJourney @ http://salaboy.wordpress.com
>>>>>  - Co-Founder @ http://www.jugargentina.org
>>>>>  - Co-Founder @ http://www.jbug.com.ar
>>>>>
>>>>>  - Salatino "Salaboy" Mauricio -
>>>>>
>>>>> _______________________________________________
>>>>> rules-users mailing list
>>>>> rules-users@lists.jboss.org
>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users@lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>
>>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



--
 - CTO @ http://www.plugtree.com
 - MyJourney @ http://salaboy.wordpress.com
 - Co-Founder @ http://www.jugargentina.org
 - Co-Founder @ http://www.jbug.com.ar

 - Salatino "Salaboy" Mauricio -

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