View Javadoc
1   package myorg.relex.one2one;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class is an example of the inverse/parent side of a one-to-one, 
7    * bi-directional relationship that allows 0..1 and changing related entities.
8    */
9   @Entity(name="RelationAuto2")
10  @Table(name="RELATIONEX_AUTO2")
11  public class Auto2 {
12  	public enum Type { CAR, TRUCK };
13  	
14  	@Id @GeneratedValue
15  	private int id;
16  	@Enumerated(EnumType.STRING)
17  	@Column(length=10)
18  	private Type type;
19  	
20  	@OneToOne(
21  			optional=true, fetch=FetchType.LAZY)
22  	private Driver2 driver;
23  	
24  	public Auto2() {}
25  	public int getId() { return id;}
26  
27  	public Type getType() { return type; }
28  	public void setType(Type type) {
29  		this.type = type;
30  	}
31  
32  	public Driver2 getDriver() { return driver; }
33  	public void setDriver(Driver2 driver) {
34  		this.driver = driver;
35  	}
36  }