0 Replies Latest reply on May 19, 2014 5:44 AM by smog

    Facts are not matching the condition

    smog Newbie

      Hi,

       

      i got very annoying problem, i have generated test project with help of jboss tools

       

      Environment: jbpm.version = 6.0.0.Final, jdk 1.7.0_25

       

      My code:

       

      public class OrgUnit implements Serializable {

        private static final long serialVersionUID = -1L;

       

        private int id;

       

           public OrgUnit() {

           }


           public OrgUnit(int id) {

               this.id = id;

           }


           public int getId() {

               return id;

           }


           public void setId(int id) {

               this.id = id;

           }

       

       

           @Override

           public boolean equals(Object o) {

               if (this == o) return true;

               if (o == null || getClass() != o.getClass()) return false;

       

               OrgUnit orgUnit = (OrgUnit) o;

       

               if (id != orgUnit.id) return false;

               return true;

           }

           @Override

           public int hashCode() {

               return id;

           }

           @Override

           public String toString() {

               return "OrgUnit{" +

                       "id=" + id +

                       "} " + super.toString();

           }

       

      ProcessMain class:

       

      KieServices ks = KieServices.Factory.get();
      KieContainer kContainer = ks.getKieClasspathContainer();
      KieBase kbase = kContainer.getKieBase("kbase");

       

      RuntimeManager manager = createRuntimeManager(kbase);
      RuntimeEngine engine = manager.getRuntimeEngine(null);
      KieSession ksession = engine.getKieSession();
      TaskService taskService = engine.getTaskService();

       

      ksession.insert(new OrgUnit(1));
      ksession.insert(new OrgUnit(2));
      ksession.fireAllRules();
      System.out.println("END");
      System.exit(0);

       

       

       

      my drl file:

       

      package com.sample.process

      rule "Your First Rule"

          when

              $orgUnit: OrgUnit()

          then

              System.out.println("XX:" + $orgUnit);

      end



      As i said everything is generated except of OrgUnit class, i think that my rule should post two debug messages, but instead of this there is only one message:


      XX:OrgUnit{id=1} com.sample.process.OrgUnit@1


      Somehow drools swallows the last inserted fact of the same type, i do not really understand why its happens. If I insert only one fact, no messages are shown at all.


      Any help is appreciated!

       

      Tnx a lot!

       

       

       

      UPD:

       

      Well, if i initialize ksession like this:

       

      KieServices ks = KieServices.Factory.get();
      KieContainer kContainer = ks.getKieClasspathContainer();
      KieSession ksession = kContainer.newKieSession("ksession1");

       

      Everything works. Can someone tell me why its happens?

       

      tnx a lot.

       

      Сообщение отредактировано: Smog