Hi,

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:

when
  $child : Child()
  $parent : Parent(child == $child)
then
  ...
end

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:

http://www.jboss.org/community/docs/DOC-11169

Excerpt:

 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?

-Chris
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to