View Javadoc
1   package myorg.relex.many2one;
2   
3   import java.io.Serializable;
4   import javax.persistence.*;
5   
6   /**
7    * This class provides an example compound primary key value that will be used in a many-to-one,
8    * uni-directional relationship.
9    */
10  @Embeddable
11  public class HousePK implements Serializable {
12  	private static final long serialVersionUID = 5213787609029123676L;
13  	@Column(name="NO")
14  	private int number;
15  	@Column(name="STR", length=50)
16  	private String street;
17  	
18  	public HousePK() {}
19  	public HousePK(int number, String street) {
20  		this.number = number;
21  		this.street = street;
22  	}
23  	
24  	public int getNumber() { return number; }
25  	public void setNumber(int number) {
26  		this.number = number;
27  	}
28  	
29  	public String getStreet() { return street; }
30  	public void setStreet(String street) {
31  		this.street = street;
32  	}
33  
34  	@Override
35  	public int hashCode() {
36  		return number + street==null?0:street.hashCode();
37  	}
38  	
39  	@Override
40  	public boolean equals(Object obj) {
41  		try {
42  			if (this==obj) { return true; }
43  			HousePK rhs = (HousePK)obj;
44  			if (street==null && rhs.street != null) { return false; }
45  			return number==rhs.number && street.equals(rhs.street);
46  		} catch (Exception ex) { return false; }
47  	}	
48  }