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 business identity. Note that it is not always easy to derive a business Id
9    * for an entity class.
10   */
11  @Entity
12  @Table(name="RELATIONEX_SHIP")
13  public class ShipByBusinessId extends Ship {
14  	@Override
15  	public int peekHashCode() {
16  		return (name==null ? 0 : name.hashCode()) + 
17  			   (created==null ? 0 : (int)created.getTime());
18  	}
19  
20  	@Override
21  	public boolean equals(Object obj) {
22  		try {
23              if (this == obj) { return logEquals(obj, true); }
24  			boolean equals = name.equals(((ShipByBusinessId)obj).name) &&
25  					created.getTime() == (((ShipByBusinessId)obj).created.getTime());
26  			return logEquals(obj, equals);
27  		} catch (Exception ex) {
28  			return logEquals(obj, false);
29  		}
30  	}
31  	
32  	@Override
33  	public String toString() {
34  		return super.toString() + 
35  				", name=" + name + 
36  				", created=" + (created==null ? 0 : created.getTime()); 
37  	}
38  }