View Javadoc
1   package myorg.relex.one2one;
2   
3   import java.util.Date;
4   
5   import javax.persistence.*;
6   
7   /**
8    * This class provides an example of the owning side
9    * of a one-to-one, bi-directional relationship.
10   */
11  @Entity
12  @Table(name="RELATIONEX_APPLICATION")
13  public class Application {
14      @Id
15      private int id;
16      @MapsId //foreign key realizes primary key
17      @OneToOne(//lack of mappedBy identifies this as owning side 
18      		  optional=false, fetch=FetchType.EAGER)
19      private Applicant applicant;
20      
21      @Temporal(TemporalType.DATE)
22      private Date desiredStartDate;
23  
24      protected Application() {}
25      public Application(Applicant applicant) {
26      	this.applicant = applicant;
27      	if (applicant != null) { 
28      		applicant.setApplication(this); //must maintain inverse side 
29      	}
30  	}
31      
32  	public int getId() { return id; }
33  	public Applicant getApplicant() { return applicant; }
34  
35  	public Date getDesiredStartDate() { return desiredStartDate; }
36  	public void setDesiredStartDate(Date desiredStartDate) {
37  		this.desiredStartDate = desiredStartDate;
38  	}
39  }