Thanks dharmendra!
We already have hashCode and equals implemented in the base class:
// ----------------------------------------------------------------------
// Equality and hashcode calculations
private int m_hashCode = Integer.MIN_VALUE;
// Calculate hashcode - this is done like this since id cannot be used to calculate it
// May be null for new objects and hash code should not change on save/load cycle...
public int hashCode()
{
if (m_hashCode == Integer.MIN_VALUE){
String tmp = dateToString(m_created, "yyyyMMddHHmmss", null);
m_hashCode = tmp.hashCode();
// log.fatal("hashCode(): " + m_hashCode + ", str=" + tmp + ", date=" + m_created);
}
return m_hashCode;
}
/**
* Simple "common" equality comparison.
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object other)
{
boolean result = false;
if (other == null) {
result = false;
}
else if (this == other) {
result = true;
}
else if ((this.getId() == null) || ((VOBase) other).getId() == null) {
result = false;
}
else {
result = this.getId().equals(((VOBase) other).getId());
// Check that business object is of the same type...
if (result) {
String myName = ((VOBase) this).getObjectModelName();
String otherName = ((VOBase) this).getObjectModelName();
result = myName.equals(otherName);
}
}
// log.fatal("equals: (" + this + " == " + other + ") = " + result);
return result;
}
You suggested merge instead of saveOrUpdate, does this have any side effects? We can try that. What did you mean by "using return reference of merge"?
|