-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Entity with proper equals/hashCode is useless Map key?
PostPosted: Thu Sep 02, 2010 6:48 pm 
Newbie

Joined: Wed Apr 30, 2008 10:03 am
Posts: 4
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();
}


Top
 Profile  
 
 Post subject: Re: Entity with proper equals/hashCode is useless Map key?
PostPosted: Wed Sep 08, 2010 3:00 pm 
Newbie

Joined: Wed Apr 30, 2008 10:03 am
Posts: 4
Anyone? I still can't figure out what I'm doing wrong :-/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.