View Javadoc
1   package myorg.relex.one2manybi;
2   
3   import java.io.Serializable;
4   
5   /**
6    * This class provides an example of an IdClass used by a child entity in a 
7    * many-to-one, bi-directional relationship where half of its primary key is
8    * derived form the parentId;
9    */
10  public class TirePK implements Serializable {
11  	private static final long serialVersionUID = -6028270454708159105L;
12  	private int car;   //shared primary key value from parent and child, name matches child rel
13  	private TirePosition position; //child primary key value unique within parent
14  	
15  	public TirePK() {}
16  	public TirePK(int carId, TirePosition position) {
17  		this.car=carId;
18  		this.position=position;
19  	}
20  	
21  	public int getAutoId() { return car; }
22  	public TirePosition getPosition() { return position; }
23  	
24  	@Override
25  	public int hashCode() {
26  		return car + (position==null?0:position.hashCode());
27  	}
28  	
29  	@Override
30  	public boolean equals(Object obj) {
31  		try {
32  			if (this==obj) { return true; }
33  			TirePK rhs = (TirePK)obj;
34  			return car==rhs.car && position==rhs.position;
35  		} catch (Exception ex) { return false; }
36  	}	
37  }