1 package myorg.relex.one2one;
2
3 import java.util.Date;
4
5 import javax.persistence.*;
6
7
8
9
10
11
12
13 @Entity
14 @Table(name="RELATIONEX_SHOWTICKETS")
15 @IdClass(ShowEventPK.class)
16 public class ShowTickets {
17 @Id
18 @Temporal(TemporalType.DATE)
19 @Column(name="TICKET_DATE")
20 private Date date;
21 @Id
22 @Temporal(TemporalType.TIME)
23 @Column(name="TICKET_TIME")
24 private Date time;
25
26 @OneToOne(optional=false, fetch=FetchType.EAGER)
27 @PrimaryKeyJoinColumns({
28 @PrimaryKeyJoinColumn(name="TICKET_DATE", referencedColumnName="date"),
29 @PrimaryKeyJoinColumn(name="TICKET_TIME", referencedColumnName="time"),
30 })
31 private ShowEvent show;
32
33 @Column(name="TICKETS")
34 private int ticketsLeft;
35
36 public ShowTickets() {}
37 public ShowTickets(ShowEvent show) {
38 this.date = show.getDate();
39 this.time = show.getTime();
40 this.show = show;
41 }
42
43 public Date getDate() { return show==null ? null : show.getDate(); }
44 public Date getTime() { return show==null ? null : show.getTime(); }
45 public ShowEvent getShow() { return show; }
46
47 public int getTicketsLeft() { return ticketsLeft; }
48 public void setTicketsLeft(int ticketsLeft) {
49 this.ticketsLeft = ticketsLeft;
50 }
51 }