-->
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: java.util.Set constains() fails
PostPosted: Sun Nov 13, 2005 5:25 am 
Newbie

Joined: Wed Jan 14, 2004 3:27 pm
Posts: 4
Hibernate version: 3.1b

Hello,
I'm trying to call a contains method over a lazy set.
All my mapped classes belongs to ParentH class that implements the following methods:
Code:
public boolean equals(Object obj) {
      
   if (obj == this) return true;
   if ( !getClass().equals(obj.getClass()) ) return false;
   
   ParentH pObj = (ParentH)obj;
   return    this.getId().equals(pObj.getId()) &&
         this.getVersion().equals(pObj.getVersion());
      
}
   
public String toString() {      
   return  getId().toString() + "-" + getVersion().toString() +  "@" + getClass().getName();
}
   
public int hashCode() {
   return toString().hashCode();
}


when I call the followin method:

Code:
public boolean isRoleSelected() {
   return  getUser().getCRoleSet().contains(getRole());
}


The result is always false.
Could someone help me please?
kiuma[/code]


Top
 Profile  
 
 Post subject: sorry, solved!
PostPosted: Sun Nov 13, 2005 6:36 am 
Newbie

Joined: Wed Jan 14, 2004 3:27 pm
Posts: 4
The problem was that i had forgotten that classes where proxyfied.
The code should be written like this way:

Code:
public boolean equals(Object obj) {
      
      if (obj == this) return true;
      if ( !(obj instanceof ParentH) ) return false;
      
      ParentH pObj = (ParentH)obj;
      return    this.getNonProxyClassName().equals(pObj.getNonProxyClassName()) &&
            this.getId().equals(pObj.getId()) &&
            this.getVersion().equals(pObj.getVersion());
      
   }
   public int hashCode() {
      return toString().hashCode();
   }
   public String toString() {
      StringBuffer sb = new StringBuffer(getId().toString())
                  .append(".")
                  .append(getVersion())
                  .append("@")
                  .append(getNonProxyClassName());
      return sb.toString();
   }
   
//    =================== Helpers =================================
   protected abstract String getNonProxyClassName();


Bye,
kiuma


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.