StatelessKnowledgeSession.execute(...) executes the command(s) and <i>finally calls dispose()</i> on the session. Use a stateful session or a global (filled with a low-salience rule) or  -  simply use the getObjects command.<br>
-W<br><br><div class="gmail_quote">On 29 July 2011 22:47, Heijink, Hank <span dir="ltr">&lt;<a href="mailto:heijink@audible.com">heijink@audible.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
I&#39;m new to Drools, so please excuse me if I&#39;m asking about the obvious--it&#39;s certainly not obvious to me. The problem is this: I use a stateless knowledge session where a list of facts is inserted. The rules that fire create new facts, and after all the rules have fired, I&#39;d like to obtain a list of all the facts (the old and the new). The best way seemed to use a query. I&#39;m using Drools 5.1 on Linux.<br>

This is part of my .drl file (without the imports):<br>
<br>
rule &quot;create badge&quot;<br>
when<br>
        Event ( eventType == EventType.SOME_EVENT_TYPE )<br>
        not BadgeState ( identifier == &quot;badge&quot; )<br>
then<br>
        insert( new BadgeState(&quot;badge&quot;) );<br>
end<br>
<br>
query &quot;all badges&quot;<br>
        aBadge : BadgeState()<br>
end<br>
<br>
This is the Java code:<br>
<br>
                StatelessKnowledgeSession ksession = StatsKnowledgeBase.getKnowledgeBase().newStatelessKnowledgeSession();<br>
<br>
                // Create a list of share events<br>
                ArrayList&lt;Event&gt; events = new ArrayList&lt;Event&gt;();<br>
                Date now = new Date();<br>
                MobileDevice aDevice = new MobileDevice(&quot;uniqueId&quot;, &quot;deviceType&quot;);<br>
                for (int i = 0; i &lt; 5; i++) {<br>
                        Event anEvent = new Event.Builder(now, aDevice, &quot;aCustomer&quot;, EventType.SOME_EVENT_TYPE).build();<br>
                        events.add(anEvent);<br>
                }<br>
<br>
                // Create the query for the badges<br>
                List&lt;Command&gt; commands = new ArrayList&lt;Command&gt;();<br>
                commands.add(CommandFactory.newInsertElements(events));<br>
            commands.add(CommandFactory.newQuery(&quot;all badges&quot;, &quot;all badges&quot;));<br>
<br>
                // Feed the events into Drools<br>
                KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);<br>
                ExecutionResults results = ksession.execute( CommandFactory.newBatchExecution(commands) );<br>
                NativeQueryResults queryResults = (NativeQueryResults)results.getValue(&quot;all badges&quot;);<br>
<br>
// At this point, queryResults is empty.<br>
<br>
                logger.close();<br>
<br>
                // Get a list of badges<br>
                List&lt;BadgeState&gt; badges = new ArrayList&lt;BadgeState&gt;();<br>
                for (Iterator&lt;QueryResultsRow&gt; i = queryResults.iterator(); i.hasNext(); ) {<br>
                        QueryResultsRow result = i.next();<br>
                        BadgeState obj = (BadgeState)result.get(&quot;aBadge&quot;);<br>
                        badges.add(obj);<br>
                }<br>
<br>
The logger shows me that the BadgeState object is created, but the query returns an empty list. I&#39;ve searched the documentation, which suggests that I&#39;m doing it right (<a href="http://drools.herod.net/drools-expert/html/ch03.html#d0e1956" target="_blank">http://drools.herod.net/drools-expert/html/ch03.html#d0e1956</a>, example 3.37), the archives of this mailinglist, and the web, so far without success.<br>

<br>
Clearly, I&#39;m missing something, and I have the nagging feeling that it&#39;s something simple...<br>
<br>
Any help is much appreciated!<br>
<br>
Best,<br>
Hank<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>