/* Copyright 2009 Ramnivas Laddad Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ //Listing A.2 Product: Something you can buy package ajia.domain; import javax.persistence.Entity; import javax.persistence.Table; import ajia.util.DomainEntity; @Entity @Table(name = "products") public class Product extends DomainEntity { private String name; private String description; private double price; public Product() { } public Product(String name, String description, double price) { this.name = name; this.description = description; this.price = price; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } @Override public String toString() { return "Product: " + name; } // ... hashCode() and equals() methods @Override public int hashCode() { return 31 + ((name == null) ? 0 : name.hashCode()); } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } Product other = (Product) obj; if (name == other.name || (name != null && name.equals(other.name))) { return true; } return false; } }