Object identity and equality System.identityHashCode(this) (Unable to start debugging on the web server) : id.hashCode(); }

Object identity and equality System.identityHashCode(this) : id.hashCode(); } } Notice how this equals() method falls back to Java identity for transient instances (if id==null) that don t have a database identifier value assigned yet. This is reasonable, because they can t possibly be equal to a detached instance, which has an identifier value. Unfortunately, this solution has one huge problem: Identifier values aren t assigned by Hibernate until an object becomes persistent. If a transient object is added to a Set before being saved, its hash value may change while it s contained by the Set, contrary to the contract of java.util.Set. In particular, this problem makes cascade save (discussed later in the book) useless for sets. We strongly discourage this solution (database identifier equality). A better way is to include all persistent properties of the persistent class, apart from any database identifier property, in the equals() comparison. This is how most people perceive the meaning of equals(); we call it by value equality. When we say all properties, we don t mean to include collections. Collection state is associated with a different table, so it seems wrong to include it. More important, you don t want to force the entire object graph to be retrieved just to perform equals(). In the case of User, this means you shouldn t include the boughtItems collection in the comparison. This is the implementation you can write: public class User { … public boolean equals(Object other) { if (this==other) return true; if ( !(other instanceof User) ) return false; final User that = (User) other; if ( !this.getUsername().equals( that.getUsername() ) ) return false; if ( !this.getPassword().equals( that.getPassword() ) ) return false; return true; } public int hashCode() { int result = 14; result = 29 * result + getUsername().hashCode(); result = 29 * result + getPassword().hashCode(); return result; } }
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.