我有三个班级:
它有以下层次结构:
public abstract class PlanItem {...}
public class Task extends PlanItem {
...
private Set<SubTask> subTasks;
...
}
public class SubTask {...}
我正在使用hibernate生成三个表:“PlanItem”,“Task”和“SubTask”。
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class PlanItem {
@Id
private String id;
}
@Entity
@SecondaryTable( name = "Task" )
public class Task extends PlanItem {
@Column( table = "Task" )
private String task_id;
@OneToMany(mappedBy = "id")
@Column( table = "Task" )
private Set<SubTask> subTasks;
}
@Entity
public class SubTask {
@Id
@ManyToOne(targetEntity = Task.class)
private String id;
}
这将生成正确的三个表,并生成以下外键关系:
alter table SubTask
add constraint FKrqtooosvfj0qtdol7arw1ur71
foreign key (id)
references PlanItem;
但我希望得到以下关系:
alter table SubTask
add constraint FKrqtooosvfj0qtdol7arw1ur71
foreign key (task_id)
references Task;
如何做到这一点?