AnsweredAssumed Answered

Implementation issues with NodeImpl

Question asked by gyro.gearless on May 10, 2010
Hi folks,

when investigating some Hibernate related performance issues, i noticed some (IMHO questionable) implementation details on class org.alfresco.repo.domain.hibernate.NodeImpl:

(1) The equals() method compares both on id and nodeRef:

    public boolean equals(Object obj)
    {
        if (obj == null)
        {
            return false;
        }
        else if (obj == this)
        {
            return true;
        }
        else if (!(obj instanceof Node))
        {
            return false;
        }
        Node that = (Node) obj;
        if (EqualsHelper.nullSafeEquals(id, that.getId()))
        {
            return true;
        }
        else
        {
            return (this.getNodeRef().equals(that.getNodeRef()));
        }
    }

I suppose this is an impedance mismatch with Hibernates notion of equality, which is based only on the id property (which also maps to the databases primary key). So i propose to either reflect this in the database (making id + nodeRef primary key), or rethink the equals() method….

(2) As said, equals() is defined in terms of id and nodeRef, but hashCode() uses uuid to compute the hash:

    public int hashCode()
    {  
        return getUuid().hashCode();
    }

This might break an well-known invariant, as we cannot guarantee that a.equals(b) implies a.hashCode()==b.hashCode().

Although this doesn't seem to cause issues right now, i guess a central class like NodeImpl should have a clean implementation….

Cheers
Gyro

Outcomes