View Javadoc
1   package myorg.relex.one2one;
2   
3   import javax.persistence.*;
4   
5   /**
6    * Provides example of one-to-one unidirectional relationship 
7    * using foreign key.
8    */
9   @Entity
10  @Table(name="RELATIONEX_PLAYER")
11  public class Player {
12  	public enum Position { DEFENSE, OFFENSE, SPECIAL_TEAMS};
13  	@Id @GeneratedValue
14  	private int id;
15  	@Enumerated(EnumType.STRING)
16  	@Column(length=16)
17  	private Position position;
18  	
19  	@OneToOne(optional=false,fetch=FetchType.EAGER)
20  	@JoinColumn(name="PERSON_ID")
21  	private Person person;
22  	
23  	public int getId() { return id; }
24  
25  	public Person getPerson() { return person; }
26  	public void setPerson(Person person) {
27  		this.person = person;
28  	}
29  
30  	public Position getPosition() { return position; }
31  	public void setPosition(Position position) {
32  		this.position = position;
33  	}
34  }