1 package ejava.examples.orm.rel.composite;
2
3 import java.io.Serializable;
4
5 import javax.persistence.Column;
6 import javax.persistence.Embeddable;
7
8 @Embeddable
9 public class MortgagePK implements Serializable {
10 private static final long serialVersionUID = -8980087154312518474L;
11 @Column(name="PK_HOUSE_ID")
12 private int houseId;
13 @Column(name="PK_MORTGAGE_ID")
14 private int mortgageId;
15
16 public MortgagePK() {}
17 public MortgagePK(int houseId, int doorId) {
18 this.houseId=houseId;
19 this.mortgageId=doorId;
20 }
21
22 public int getHouseId() { return houseId; }
23 public int getMortgageId() { return mortgageId; }
24
25 @Override
26 public int hashCode() {
27 return houseId + mortgageId;
28 }
29
30 @Override
31 public boolean equals(Object obj) {
32 try {
33 if (obj==null) { return false; }
34 if (this==obj) { return true; }
35 MortgagePK rhs = (MortgagePK)obj;
36 return houseId==rhs.houseId && mortgageId==rhs.mortgageId;
37 } catch (Exception ex) { return false; }
38 }
39 }