All relevant fields from the object should be included in the hashCode method. Derived fields may be excluded. In general, any field used in the equals method must be used in the hashCode method.
public class LineItemId implements Serializable{
private static final long serialVersionUID = 1L;
private int orderId;
private int productId;
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37).append(orderId).append(productId).toHashCode();
}
...
No comments:
Post a Comment