我有一个Employee
课程。 Worker
类扩展Employee
,Leader
类扩展Worker
。
每个Leader
都有一个列表public List workersResponsibleFor = new ArrayList<>();
。我想创建一个Join表,以说明Leader
是否对一个或多个Workers
负责。
@Entity
@Inheritance
@DiscriminatorColumn(name="EMP_TYPE")
@Table(name="EMPLOYEES")
public abstract class Employee implements Printable, Serializable {
@Id
@GeneratedValue
@Column(name = "employee_id", unique = true)
private int id;
@Column(name = "position")
@Enumerated(EnumType.STRING)
private Position position;
@Column(name = "name")
private String name;
@Column(name = "salary")
private Double salary;
@Transient
public List<Project> projectsWorkingOn = new ArrayList<>();
public Employee() {
}
}
Worker
:
@Entity
public class Worker extends Employee {
@Id
@GeneratedValue
@Column(name = "worker_id", unique = true)
private int id;
public Worker() {
}
}
Leader
:
@Entity
public abstract class Leader extends Worker {
public Leader() {
}
public Leader(Position position, String name, Double salary) {
super(position, name, salary);
}
@OneToMany
@JoinTable(name="WORKERS_RESPONSIBLE_FOR",
joinColumns = {@JoinColumn(name="responsible_for")})
public List<Worker> workersResponsibleFor = new ArrayList<>();
}
我敢肯定,Leader
类中的List注释是错误的,因为每次尝试使用它时我都会遇到很多错误。如何正确地对其进行注释,将责任收集到新的联结表中?