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 a the owning entity of a
9    * one-to-one, uni-directional relationship where the dependent's
10   * primary key is derived from the parent, the parent uses
11   * a composite primary key, and the dependent used an @EmeddedId
12   * and @MapsId.
13   */
14  @Entity
15  @Table(name="RELATIONEX_BOXOFFICE")
16  public class BoxOffice {
17  	@EmbeddedId 
18  	private ShowEventPK pk; //will be set by provider with help of @MapsId
19  	
20  	@OneToOne(optional=false, fetch=FetchType.EAGER)
21  	@MapsId //provider maps this composite FK to @EmbeddedId PK value
22  	private ShowEvent show;
23  	
24  	@Column(name="TICKETS")
25  	private int ticketsLeft;
26  
27  	protected BoxOffice() {}
28  	public BoxOffice(ShowEvent show) {
29  		this.show = show;
30  	}
31  
32  	public Date getDate() { return show==null ? null : show.getDate(); }
33  	public Date getTime() { return show==null ? null : show.getTime(); }
34  	public ShowEvent getShow() { return show; }
35  
36  	public int getTicketsLeft() { return ticketsLeft; }
37  	public void setTicketsLeft(int ticketsLeft) {
38  		this.ticketsLeft = ticketsLeft;
39  	}
40  }