1 package org.myorg.jpatickets.bo;
2
3 import java.io.Serializable;
4 import java.math.BigDecimal;
5
6 import javax.persistence.*;
7
8 @SuppressWarnings("serial")
9 @Entity
10 @Table(name="JPATICKETS_TICKET")
11 @NamedQueries({
12 @NamedQuery(name="JPATicketTicket.findTickets",
13 query="select t from Ticket t where t.seat in :seats")
14 })
15 @IdClass(TicketPK.class)
16 public class Ticket implements Serializable {
17 @Id
18 @ManyToOne(fetch=FetchType.EAGER, optional=false)
19 @JoinColumn(name="EVENT_ID")
20 private Event event;
21
22 @Id
23 @OneToOne(
24
25 fetch=FetchType.LAZY,
26 optional=false)
27 @JoinColumns({
28 @JoinColumn(name="VENUE_ID"),
29 @JoinColumn(name="SECTION"),
30 @JoinColumn(name="ROW"),
31 @JoinColumn(name="POSITION"),
32 })
33 private Seat seat;
34
35 @Column(name="PRICE", precision=7, scale=2)
36 private BigDecimal price;
37
38 @Column(name="SOLD", nullable=false)
39 private boolean sold;
40
41 protected Ticket() {}
42 public Ticket(Event event, Seat seat) {
43 this.event = event;
44 this.seat = seat;
45 }
46
47 public Event getEvent() { return event; }
48 public Seat getSeat() { return seat; }
49
50 public BigDecimal getPrice() { return price; }
51 public void setPrice(BigDecimal price) {
52 this.price = price;
53 }
54
55 public boolean isSold() { return sold; }
56 public void setSold(boolean sold) {
57 this.sold = sold;
58 }
59
60 @Override
61 public String toString() {
62 StringBuilder builder = new StringBuilder();
63 builder.append("Ticket [event=").append(event)
64 .append(", seat=").append(seat)
65 .append(", price=").append(price)
66 .append(", sold=").append(sold)
67 .append("]");
68 return builder.toString();
69 }
70
71
72 }