Search code examples
javadrools

Get related objects of different classes in drools kSession


I have two classes, I created 2 objects of Class1 i.e. obj1 and obj2 and four objects of Class2 i.e. c1obj1, c1obj2 , c2obj1 , c2obj2 and have passed these objects in kSession.

Now, in first rule i want to get obj1 of Class1 together with c1obj1 and c1obj2 of Class2 similarly for obj2?

a : Class1(flag == 0 , cid : class1Id )
b : Class2(id : cid)

I am trying to do it this way but getting an error.


Solution

  • If you need to find objects of Class2 with an id that matches the id of Class1 you must write

    a : Class1( flag == 0 , $cid : id )  # Class1 with fields flag and id
    b : Class2( id == $cid )             # Class2 with field id