title: Drools- Inserting the multiple facts of the same type, with one rule
body: <p>I am very new to Drools and I have completed some of the tutorials found online and read the docs. I am sure what I am about to explain has a trivial solution that I have missed but I will lay it out regardless.</p>
  
  <p>I have a single rule in my drools file and an object that reads its info from a text file.</p>
  
  <p>The code looks similar to this:</p>
  
  <pre><code>   public static final void main(String[] args) {
          try {
              ObjectArchive arch = ArchiveFactory.openArchive(new File("dwc.txt"));
              Iterator&lt;Object&gt; iter = arch.iteratorDwc();
  
              // load up the knowledge base
              KnowledgeBase kbase = readKnowledgeBase();
              StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
              KnowledgeRuntimeLogger logger =  KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
              while(iter.hasNext()) {
                  Object dwcRecord = iter.next();
                  ksession.insert(dwcRecord);
              }
              System.out.println(ksession.getFactCount());
              ksession.fireAllRules();
              logger.close();
          } catch (Throwable t) {
              t.printStackTrace();
          }
      }
  
      private static KnowledgeBase readKnowledgeBase() throws Exception {
          KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
          kbuilder.add(ResourceFactory.newClassPathResource("dwcrules.drl"), ResourceType.DRL);
          KnowledgeBuilderErrors errors = kbuilder.getErrors();
          if (errors.size() &gt; 0) {
              for (KnowledgeBuilderError error: errors) {
                  System.err.println(error);
              }
              throw new IllegalArgumentException("Could not parse knowledge.");
          }
          KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
          kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
          return kbase;
      }
  </code></pre>
  
  <p>I have a simple rules file that checks if a property of said object is not null and prints out the object if this is true.</p>
  
  <p>Now, the problem.</p>
  
  <p>If I add one object (no while loop) then the rule is fired and all is well. However, if I add multiple objects to the session and then fire the rules it tends to just grab the last one, or fire but print out a single null.</p>
  
  <p>So, why is it that I am unable to add multiple facts of the same type? Or what am I missing that stops me from being able to fire the same rule on multiple facts?</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: Sorry, here is the rule:</p>
  
  <pre><code>rule "Scientific Name"
  when 
      dwc : Object(dwc.getScientificName != null)
  then
      System.out.println(dwc);
   end
  </code></pre>