title: Drools - Inserting Function-Created Object in Memory
body: <p>In a Drools DRL file I have a function that returns a custom object.
  In a rule, I call this function and then insert the function result into memory.
  However, subsequent rules do not then seem to pick up this inserted object.</p>
  
  <p>If I create the object in the rule (rather than via a function) and insert it, subsequent rules are able to see it and run fine.</p>
  
  <p>Code example below:</p>
  
  <pre><code>declare SomeObject
      value : String
  end
  
  
  function SomeObject createSomeObject() {
      SomeObject obj = new SomeObject();
      obj.setValue("something");
      return obj;
  }
  
  
  rule "run first" ruleflow-group "testrules-test"
  dialect "mvel"
  when
      eval(true)
  then
      insert(createSomeObject());     // this does not trigger the "object exists" rule
      insert(new SomeObject());       // this triggers the "object exists" rule
  end
  
  
  rule "object exists" ruleflow-group "testrules-test"
  dialect "mvel"
  when
      SomeObject()
  then
      info("the object exists");
  end
  </code></pre>
  
  <p>(Note that I have shown both insert methods but of course have not run with both active).</p>
  
  <p>My obvious question is why does the object created by the function not get inserted into memory?</p>
  
  <p>This also leads me onto the use of functions in Drools rules; should they be avoided or are there no performance or behavioural advantages or disadvantages?</p>
  
  <p>Thanks.</p>