JBoss Community

Re: Entity hashCode and equals overriding

created by fabio valsecchi in EJB3 Development - View the full discussion

I've just fix the problem! I've changed the code in this way:

 

-------------------------------------------------------

@Override

          public boolean equals(Object o) {

             if (o==this)

                 return true;

             if (o instanceof Book) {

                       if (this.isbn.compareTo(((Book) o).getIsbn()) == 0)

                                 return true;

                       else return false;

             }

             return false;

          }

-------------------------------------------------------

 

The problem was the comparison between string! Now I use the compareTo() method and everything correctly works.

 

Thank you for your time Piotr!

Reply to this message by going to Community

Start a new discussion in EJB3 Development at Community