When you use "==" in a DRL field constraint (not eval), drools always translates it into an .equals() call.

   Having said that, there might be other problems, since drools must rely on object identity for some internal data structures... for instance, we use IdentityMaps for mapping FactHandles and the actual fact objects, etc.

   We would need to test this and see what can be done. Could you please open a JIRA and attach a test case so that we can reproduce the problem?


2009/4/26 CK <>

I'm testing out some simple codes using Hibernate and Drools 5 and I'm hitting an issue with hibernate proxy objects.

With the newer version of hibernate, Javassist is used to proxy some hibernate objects.  By doing this, hibernate objects essentially cannot use == comparisons, which is fine.

However, this is causing issue in equality checks within Drools 5 LHS evaluations of hibernate persistent objects.

Let's say for example I have the following Hibernate objects:

class Parent {
       Child child;

class Child {
       String name;

normally, if you output Parent.child, it should be Child.class.  But under Hibernate, the child property in Parent may be proxied and enhanced with Javassist, thus making Parent.child.class to be something like "Child_$$_javassist_75".

Inside Drools, in the LHS:

 $child : Child()
 $parent : Parent(child == $child)

Assume that I have insert separate Child instances here that were retrieved from an Hibernate query directly.  Assume that I have also inserted Parent instances that were retrieved from a separate query without eager fetching.  Given this particular case, the above rule would not match even though it technically should.  Under normal java code, using equality, the parent's child is equal to the child.

According to MVEL language, which Drools LHS may not necessarily be using, equality between two objects are compared using values.  Not sure exactly what that means.

Either way, this seems to be a rather unfortunate problem for using Drools to work with Hibernate objects.  Older hibernate versions didn't cause this problem.

It seemed like jBPM had a similar problem according to the following doc:


 Object identity and object equality

MAKE SURE TO USE ALWAYS .equals AND NEVER == comparisons in the Java code.

Typically, in the PVM Java objects, we want to use the default object identity as the object equality.  But hibernate persistence breaks this (even within the scope of one hibernate session) because of the proxies.  So we have to apply a trick in order to make the comparison between a persistent object and its proxy return true.  See jBPM 3 class EqualsUtil for that trick.

So my question is whether Drools uses equality or identity when it comes to comparing values in LHS constraints.  Is there a way to get around this issue?

rules-users mailing list

 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @