In my attempt to solve a problem when retrieving object references (collection
and simple) from a domain/persistent class, I looked up Identity.java class
source as I suspect identity object as the source of the problem.
The equals method of the identity class does not seem to take the object's real
class type (m_objectsRealClass attrib) into account when comparing two
identities. Is the equals method correctly implemented ?
Equals method in Identity.java:
public boolean equals(final Object obj)
{
if(this == obj) return true;
boolean result = false;
if (obj instanceof Identity)
{
final Identity id = (Identity) obj;
result = m_objectsTopLevelClass.equals(id.m_objectsTopLevelClass)
&& isTransient == id.isTransient;
if(result)
{
final Object[] otherPkValues = id.m_pkValues;
result = m_pkValues.length == otherPkValues.length;
if(result)
{
for (int i = 0; result && i < m_pkValues.length; i++)
{
result = (m_pkValues[i] == null) ? (otherPkValues[i] ==
null)
: m_pkValues[i].equals(otherPkValues[i]);
// special treatment for byte[]
if (!result && m_pkValues[i] instanceof byte[] &&
otherPkValues[i] instanceof byte[])
{
result = Arrays.equals((byte[]) m_pkValues[i],
(byte[]) otherPkValues[i]);
}
}
}
}
}
return result;
}
Javadoc for Identity.java class:
public class Identity
extends java.lang.Object
implements java.io.Serializable
Represents the identity of an object.
It's composed of:
class of the real object
top-level class of the real object (could be an abstract class or interface or
the class of the object itself), used to make an object unique across extent
classes
an array of all primary key value objects
a flag which indicates whether this is a transient Identity (identity of a
non-persistent, "new" object) or a persistent Identity (identity object of a
persistent, "already written to datastore" object).
Thanks and Regards,
Gautam.