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="RelationAuto")
10  @Table(name="RELATIONEX_AUTO")
11  public class Auto {
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  			mappedBy="auto", 
22  			optional=true, fetch=FetchType.LAZY)
23  	private Driver driver;
24  	
25  	public Auto() {}
26  	public int getId() { return id;}
27  
28  	public Type getType() { return type; }
29  	public void setType(Type type) {
30  		this.type = type;
31  	}
32  
33  	public Driver getDriver() { return driver; }
34  	public void setDriver(Driver driver) {
35  		this.driver = driver;
36  	}
37  }