My entities do not "behave" as Map keys. Duplicates are entered with map.put(assetTypeCustomAttribute, value) using the same instance as a key, and map.contains(assetTypeCustomAttribute) always returns false. I really need a second pair of eyes, been struggling with this for a couple of days. Here's how I use an entity named AssetTypeCustomAttribute as a map key:
Code:
<class name="Asset" table="ASSETS">
<id name="id" column="AS_ID">
<generator class="native" />
</id>
<!-- ... -->
<map name="customAttributes" table="ASSET_CUSTOM_ATTRIBUTES_VALUES" cascade="all-delete-orphan" inverse="false" lazy="true" sort="natural">
<key column="ACAV_ASID" not-null="true" />
<map-key-many-to-many column="ACAV_CAID" class="AssetTypeCustomAttribute"/>
<element type="string" column="ACAV_VALUE"/>
</map>
</class>
My AssetTypeCustomAttribute has the following hashCode/equals implementations:
Code:
@Override
public int hashCode() {
return new HashCodeBuilder(11, 73)
.append(this.getName())
.toHashCode();
}
@Override
public boolean equals(Object o) {
if (o == null) { return false; }
if (o == this) { return true; }
if (!(o instanceof AssetTypeCustomAttribute)) {
return false;
}
AssetTypeCustomAttribute other = (AssetTypeCustomAttribute) o;
return new EqualsBuilder()
.append(this.getName(), other.getName())
.isEquals();
}