I just asked the new hbm2java (extensions 2.1) to generate equals:
Code:
<meta attribute="implement-equals">true</meta>
via a non-id property as recommended in the Hibernate pages: see "Seperating object id and business key" on
http://hibernate.org/109.htmlCode:
<property name="name" type="java.lang.String" column="name" length="256">
<meta attribute="field-description">Names are unique and so provide an alternate way to dsrcId for referring to a DataSlice.</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
Looking at the generated code I see:
Code:
public boolean equals(Object other) {
if ( (other == other ) ) return true;
if ( !(other instanceof Persistent_DataSlice) ) return false;
Persistent_DataSlice castOther = (Persistent_DataSlice) other;
return new EqualsBuilder()
.append(this.getName(), castOther.getName())
.isEquals();
}
And the very first line of code reads:
Code:
if ( (other == other ) ) return true;
Now my question: when will that not be true?! In other words the generated equals() method says this instance is equal to every other object!
Yeah, I know I can write my own Velocity template and guess I'll have to do so, but this looks like a bug to me.