<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Thanks for that, Wolfgang. I have been working on something else for a few days, but just switched over to batch execution, and that is giving me some appropriate results (my tests are passing).</div><div><br></div><div>Which leads me to the question ...</div><div><br></div><div>Given that Example 3.4.1 in the Drools 5.5.0.Final user guide does not compile, is that because there is a bug in the implementation of command execution? Or is it a bug in the example. i.e.</div><div><ol><li>The results should just not be assigned to anything?</li><li>The results (an ArrayList containing the facts which were just inserted) should be assigned to a List of Object?</li><li>The example should just be removed from the user guide, as it is no longer a valid/recommended approach?</li></ol></div><div><br></div><div>Anybody with thoughts on that? Assuming that the answer is a documentation fix, I’ll be happy to correct it appropriately and submit a pull request.</div><div><br></div><div>Cheers,</div><div><br></div><div>Steve</div><div><br></div><div> </div><div><br></div><br><div><div>On 4 Dec 2013, at 12:24, Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I think you have to put your insert command into a list<br> List<Command<?>> cmds = new ArrayList();<br>and pass this via batch execution<br> CommandFactory.newBatchExecution( cmds )<br><br>-W<br><br>On 04/12/2013, Stephen Masters <<a href="mailto:stephen.masters@me.com">stephen.masters@me.com</a>> wrote:<br><blockquote type="cite">Hi folks,<br><br>Can anyone explain how stateless session execution results should work?<br>Working through the docs and tracing the code, it’s getting a bit<br>confusing.<br><br>Firstly, according to the user manual, one should be able to insert a list<br>of facts as a Command, and get an instance of ExecutionResults back, which<br>can then be queried. Here’s the example code:<br>StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();<br><br>Command cmd = CommandFactory.newInsertElements( Arrays.asList( Object[] {<br><br> new Cheese( "stilton" ),<br><br> new Cheese( "brie" ),<br><br> new Cheese( "cheddar" ),<br><br> });<br><br>ExecutionResults bresults = ksession.execute( cmd );<br><br>That doesn’t compile, so I fixed it as follows:<br><br> Command cmd = CommandFactory.newInsertElements( Arrays.asList(<br> new Cheese( "stilton" ),<br> new Cheese( "brie" ),<br> new Cheese( "cheddar" )<br> ));<br> ExecutionResults bresults = ksession.execute( cmd );<br><br>This does now compile, but running it throws a ClassCastException:<br><span class="Apple-tab-span" style="white-space:pre">        </span>java.lang.ClassCastException: java.util.ArrayList cannot be cast to<br>org.drools.runtime.ExecutionResults<br><br>Taking a look through the Drools code, it would appear that Command has a<br>generic type, which in the case of an InsertElementsCommand is:<br>GenericCommand<Collection<FactHandle>><br><br>In turn, the execute command in StatelessKnowledgeSessionImpl casts its<br>result to that generic type:<br><span class="Apple-tab-span" style="white-space:pre">        </span>public <T> T execute(Command<T> command) {<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Object o = ((GenericCommand) command).execute( context );<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>...<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>return (T) o;<br><br>So the ClassCastException is because the execute method returns an ArrayList<br>of FactHandle instead of an ExecutionResults.<br><br>I’m assuming that I must have got the wrong end of the stick somewhere, so<br>what should I be doing to get an ExecutionResults from a stateless session,<br>which I can then query?<br><br>Cheers,<br><br>Steve<br></blockquote><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users<br></blockquote></div><br></body></html>