1 package ejava.jpa.examples.cache; 2 3 import javax.persistence.*; 4 5 import org.hibernate.annotations.Cache; 6 import org.hibernate.annotations.CacheConcurrencyStrategy; 7 8 @Entity 9 @Table(name="JPACACHE_ZIPADDR") 10 @Cacheable(true) 11 @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) 12 public class ZipAddress { 13 @Id 14 @Column(length=10) 15 private String zip; 16 @Column(length=32, nullable=false) 17 private String city; 18 19 protected ZipAddress() {} 20 public ZipAddress(String zip, String city) { 21 this.zip=zip; 22 this.city=city; 23 } 24 25 public ZipAddress(String zip) { 26 this.zip=zip; 27 } 28 public String getZip() { return zip; } 29 public String getCity() { return city; } 30 31 @Override 32 public String toString() { 33 return zip + "=" + city; 34 } 35 36 @Override 37 public int hashCode() { 38 return zip==null? 0 : zip.hashCode(); 39 } 40 41 @Override 42 public boolean equals(Object obj) { 43 if (obj==null) { return false; } 44 if (obj==this) { return true; } 45 if (!(obj instanceof ZipAddress)) { return false; } 46 ZipAddress rhs = (ZipAddress) obj; 47 return zip==null ? rhs.zip==null : zip.equals(rhs.zip); 48 } 49 }