When defining Drools rules, what is the best way to accommodate object graphs?
Say I have the following Entity object graph with a many-to-many relationship:
User <- Group -> Value
and I have the following contrived rule:
rule "hasPurpleValue"
$u : User()
$g : Group() from $u.groups
$v : Value(color == 'Purple') from $g.values
then
//...
end
I can insert a user into the ksession as follows:
//build user...
User user = new User();
Group group = new Group();
Value value = new Value("Purple");
group.setValue(value);
user.addGroup(group);
ksession.insert(user);
then update them:
ksession.update(ksession.getFactHandle(user), user);
But what if I change the Value object directly to "Orange"
, the Value does not have a FactHandle as it was inserted with the user as the root. Is there a better way to define the rules and insert the entities such that I can independently alter the Entities and Drools will evaluate the outcome?