View Javadoc
1   package myorg.relex.collection;
2   
3   
4   import javax.persistence.*;
5   
6   /**
7    * This class is provides an example of an entity that implements hashCode/equals 
8    * using its database assigned primary key. Note the PK is not assigned until the 
9    * entity is inserted into the database -- so there will be a period of time prior
10   * to persist() when all instances of this class report the same hashCode/equals. 
11   */
12  @Entity
13  @Table(name="RELATIONEX_SHIP")
14  public class ShipByPK extends Ship {
15  	@Override
16  	public int peekHashCode() {
17  		return id;
18  	}
19  
20  	@Override
21  	public boolean equals(Object obj) {
22  		try {
23              if (this == obj) { return logEquals(obj, true); }
24  			boolean equals = id==((ShipByPK)obj).id;
25  			return logEquals(obj, equals);
26  		} catch (Exception ex) {
27  			return logEquals(obj, false);
28  		}
29  	}
30  }