1 package myorg.relex.one2many;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.persistence.*;
7
8
9
10
11
12 @Entity
13 @Table(name="RELATIONEX_BUS")
14 public class Bus {
15 @Id
16 private int number;
17
18 @OneToMany
19 @JoinTable(
20 name="RELATIONEX_BUS_RIDER",
21 joinColumns={@JoinColumn(name="BUS_NO")},
22 inverseJoinColumns={@JoinColumn(name="RIDER_ID")}
23 )
24 private List<Rider> passengers;
25
26 protected Bus() {}
27 public Bus(int number) {
28 this.number = number;
29 }
30
31 public int getNumber() { return number; }
32
33 public List<Rider> getPassengers() {
34 if (passengers==null) { passengers = new ArrayList<Rider>(); }
35 return passengers;
36 }
37 public void setPassengers(List<Rider> passengers) {
38 this.passengers = passengers;
39 }
40 }