1 package myorg.entityex.annotated;
2
3 import java.io.Serializable;
4
5 import javax.persistence.Column;
6 import javax.persistence.Embeddable;
7
8 @Embeddable
9 public class CowPK implements Serializable {
10 private static final long serialVersionUID = 1L;
11 @Column(name="HERD", length=16)
12 private String herd;
13 private String name;
14
15 public CowPK(){}
16 public CowPK(String herd, String name) {
17 this.herd = herd;
18 this.name = name;
19 };
20
21 public String getHerd() { return herd; }
22 public String getName() { return name; }
23 public void setName(String name) { this.name = name; }
24
25 @Override
26 public int hashCode() {
27 return herd.hashCode() + name.hashCode();
28 }
29
30 @Override
31 public boolean equals(Object obj) {
32 try {
33 return herd.equals(((CowPK)obj).herd) &&
34 name.equals(((CowPK)obj).name);
35 } catch (Exception ex) {
36 return false;
37 }
38 }
39
40 }