1 package ejava.projects.edmv.bo;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import javax.persistence.*;
8
9
10
11
12
13
14 @Entity(name="VehicleRegistration")
15 @Table(name="EDMV_VREG")
16 @SuppressWarnings("serial")
17 public class VehicleRegistration implements Serializable {
18 @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
19 private long id;
20
21 @Column(length=20)
22 private String vin;
23
24 @ManyToMany()
25 @JoinTable(name="EDMV_VREG_OWNER_LINK",
26 joinColumns={@JoinColumn(name="VEHICLE_ID")},
27 inverseJoinColumns={@JoinColumn(name="OWNER_ID")}
28 )
29 private List<Person> owners = new ArrayList<Person>();
30
31
32 public VehicleRegistration() {}
33 public VehicleRegistration(long id) {
34 this.id = id;
35 }
36
37 public long getId() {
38 return id;
39 }
40
41 @SuppressWarnings("unused")
42 private void setId(long id) {
43 this.id = id;
44 }
45
46 public String getVin() {
47 return vin;
48 }
49 public void setVin(String vin) {
50 this.vin = vin;
51 }
52
53 public List<Person> getOwners() {
54 return owners;
55 }
56 public void setOwners(List<Person> owners) {
57 this.owners = owners;
58 }
59
60 public String toString() {
61 StringBuilder text = new StringBuilder();
62
63 text.append("id=" + id);
64 text.append(", vin=" + vin);
65 text.append(", owners={");
66 for (Person p : owners) {
67 text.append(p + ",");
68 }
69 text.append("}");
70
71 return text.toString();
72 }
73 }