[rules-users] Question about Object.equals and modifyRetract/Insert

Michal Bali michalbali at gmail.com
Mon Oct 13 18:00:38 EDT 2008


Hello,

Let's say we have a simple BeanA with one property that is part of
equal/hashCode method e.g.:
----------------------------------------
public class BeanA {
  int someProperty;

  public int getSomeProperty() {
    return someProperty;
  }
  public void setSomeProperty(int someProperty) {
    this.someProperty = someProperty;
  }

  @Override
  public boolean equals(final Object other) {
    if (this == other)
      return true;
    if (!(other instanceof BeanA))
      return false;
    BeanA castOther = (BeanA) other;
    return new EqualsBuilder().append(someProperty,
        castOther.someProperty).isEquals();
  }

  @Override
  public int hashCode() {
    return new HashCodeBuilder(228431015, 1383549405).append(
        someProperty).toHashCode();
  }
}
------------------------------------
This bean is inserted into the working memory. Is it something wrong with
doing?:
wm.modifyRetract(beanA);
beanA.setSomeProperty(22); //this is changing the object equality key
wm.modifyInsert(beanAHandle, beanA);

I know that simple update is not allowed:
beanA.SetSomeProperty(22);
update(beanAHandle, beanA); //this is wrong

I guess there is no difference if this code is outside the rule engine or
inside (e.g. in a rule consequence).

Thank you,
Best Regards,
Michal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081013/080e8f9a/attachment.html 


More information about the rules-users mailing list