Hibernate version: 3.1-beta
Dear list,
When I trigger generation of the equals method in my mappings like this:
Code:
<id name="id" type="java.lang.Long">
<meta attribute="use-in-equals">true</meta>
<generator class="native" />
</id>
then hbm2java produces the following code:
Code:
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof BaseRelatie) ) return false;
BaseRelatie castOther = ( BaseRelatie ) other;
return ( (this.getId()==castOther.getId()) ||
( this.getId()!=null && castOther.getId()!=null
&& this.getId().equals(castOther.getId()) ) );
}
The
Code:
(this.getId()==castOther.getId()) ||
fragment implies that 2 instances are equal when both ids are null. So when I add 2 (not yet persisted) instances to a Collection, this fragment will cause the first instance to be overwritten by the second. Therefore this fragment should be removed IMO.
Kind regards,
Bas