spring jpa add field to many to many table

Solutions on MaxInterview for spring jpa add field to many to many table by the best coders in the world

showing results for - "spring jpa add field to many to many table"
Dylan
31 Apr 2016
1@Entity
2public class Employer {
3
4    @Id
5    @GeneratedValue(strategy = GenerationType.IDENTITY)
6    private int id;
7
8    @OneToMany(mappedBy = "employer")
9    private List<EmployerDeliveryAgent> deliveryAgentAssoc;
10
11    // other properties and getters and setters
12}
13
14@Entity
15public class DeliveryAgent {
16
17    @Id
18    @GeneratedValue(strategy = GenerationType.IDENTITY)
19    private int id;
20
21    @OneToMany(mappedBy = "deliveryAgent")
22    private List<EmployerDeliveryAgent> employerAssoc;
23
24    // other properties and getters and setters
25}
26
27@Entity
28@Table(name = "employer_delivery_agent")
29@IdClass(EmployerDeliveryAgentId.class)
30public class EmployerDeliveryAgent {
31
32    @Id
33    @ManyToOne
34    @JoinColumn(name = "employer_id", referencedColumnName = "id")
35    private Employer employer;
36
37    @Id
38    @ManyToOne
39    @JoinColumn(name = "delivery_agent_id", referencedColumnName = "id")
40    private DeliveryAgent deliveryAgent;
41
42    @Column(name = "is_project_lead")
43    private boolean isProjectLead;
44}
45
46public class EmployerDeliveryAgentId implements Serializable {
47
48    private int employer;
49    private int deliveryAgent;
50
51    // getters/setters and most importantly equals() and hashCode()
52}