I want to implement relationship between Ticket and Flight relationship between the two entities.
A Flight has many tickets which is fine and can be achieved by
`Settickets = new HashSet(0);
@OneToMany
public Set<Ticket> getTickets() {
return tickets;
}
public void setTickets(Set<Ticket> tickets) {
this.tickets = tickets;
}`
But how should I implement Ticket has ONLY ONE Flight associated with it ?
I am not sure if Implementing like below would solve the problem. Inside Ticket,java
Flight flight;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="ticket_id")
public Flight getFlight() {
return flight;
}
public void setFlight(Flight flight) {
this.flight = flight;
}
`
Any ideas?
You should go this way:
In
Flight:And in
Ticket