View Javadoc
1   package myorg.relex.one2one;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class provides an example of the owning/dependent side of a one-to-one
7    * relationship where the inverse/parent represents a 0..1 or changing relation.
8    */
9   @Entity
10  @Table(name="RELATIONEX_DRIVER")
11  public class Driver {
12  	@Id @GeneratedValue
13  	private int id;
14  	@Column(length=20)
15  	private String name;
16  	
17  	@OneToOne(
18  			optional=false,    //we must have the auto for this driver
19  			fetch=FetchType.EAGER)
20  	private Auto auto;
21  	
22  	protected Driver() {}
23  	public Driver(Auto auto) {
24  		this.auto = auto;
25  	}
26  	
27  	public int getId() { return id; }
28  
29  	public Auto getAuto() { return auto; }
30  	public void setAuto(Auto auto) { //drivers can switch Autos
31  		this.auto = auto;
32  	}
33  
34  	public String getName() { return name; }
35  	public void setName(String name) {
36  		this.name = name;
37  	}
38  }