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 join table.
8    */
9   @Entity
10  @Table(name="RELATIONEX_MEMBER")
11  public class Member {
12  	public enum Role { PRIMARY, SECONDARY};
13  
14  	@Id @GeneratedValue
15  	private int id;
16  	
17  	@OneToOne(optional=false,fetch=FetchType.LAZY)
18  	@JoinTable(name="RELATIONEX_MEMBER_PERSON",
19  		joinColumns={
20  			@JoinColumn(name="MEMBER_ID", referencedColumnName="ID"),
21  		}, inverseJoinColumns={
22  			@JoinColumn(name="PERSON_ID", referencedColumnName="ID"),
23  		}
24  	)
25  	private Person person;
26  
27  	@Enumerated(EnumType.STRING)
28  	@Column(length=16)
29  	private Role role;
30  	
31  	protected Member() {}
32  	public Member(Person person) {
33  		this.person = person;
34  	}
35  	
36  	public int getId() { return id; }
37  	public Person getPerson() { return person; }
38  
39  	public Role getRole() { return role; }
40  	public void setRole(Role role) {
41  		this.role = role;
42  	}
43  }