View Javadoc
1   package myorg.relex.collection;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class is an example of an entity that will be referenced from the parent in its relationship
7    * through a Map which uses a value unique to that parent.
8    */
9   @Entity
10  @Table(name="RELATIONEX_POSITION")
11  public class Position {
12  	@Id @GeneratedValue
13  	private int id;
14  	
15  	@Column(length=12, nullable=false)
16  	private String position; //this is not unique within this table
17  	
18  	@Column(length=32, nullable=false, unique=true)
19  	private String player; //this is unique within the table
20  	
21  	protected Position() {}
22  	public Position(String position, String player) {
23  		this.position = position;
24  		this.player = player;
25  	}
26  
27  	public int getId() { return id; }
28  
29  	public String getPosition() { return position; }
30  	public void setPosition(String position) { this.position = position; }
31  
32  	public String getPlayer() { return player; }
33  	public void setPlayer(String player) {
34  		this.player = player;
35  	}
36  	
37  	@Override
38  	public int hashCode() {
39  		return position==null?0:position.hashCode() + player==null?0:player.hashCode(); 
40  	}
41  	
42  	@Override
43  	public boolean equals(Object obj) {
44  		try {
45  			if (this == obj) { return true; }
46  			Position rhs = (Position) obj;
47  			if (position==null || player==null) { return false; }
48  			return position.equals(rhs.position) && player.equals(rhs.player);
49  		} catch (Exception ex) { return false; }
50  	}
51  }