将Employee Class映射到Task Class作为OneToMany映射。 (具有Task对象列表的员工。)
Employee类扩展了Person类。
类图如下,
我尝试使用以下代码作为 *表每具体类方法* ,但它没有工作
Person.java
@Entity
@Table(name = "Person ")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Person {
@Id
@GeneratedValue
private Long id;
private String name;
private int age;
// implemented getters and setters
}
Employee.java
@Entity
@Table(name="Employee")
@AttributeOverrides({
@AttributeOverride(name="id", column=@Column(name="id"))
})
public class Employee extends Person{
@Id
@GeneratedValue
private Long id;
private String jobName;
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL)
private List<Task> tasks;
// implemented getters and setters
}
Task.java
@Entity
@Table(name="Task")
public class Task {
@Id
@GeneratedValue
private Long id;
private String taskName;
private double deadLine;
@ManyToOne
@JoinColumn(name = "employeeID")
private Employee employee;
// implemented getters and setters
}
如何为此执行hibernate映射,