I have three classes:
It has the following hierachy:
public abstract class PlanItem {...}
public class Task extends PlanItem {
...
private Set<SubTask> subTasks;
...
}
public class SubTask {...}
I am using hibernate to generate three tables: "PlanItem", "Task" and "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;
}
This generates the correct three tables and it generates the following foreign key relation:
alter table SubTask
add constraint FKrqtooosvfj0qtdol7arw1ur71
foreign key (id)
references PlanItem;
but I would like to get the following relation:
alter table SubTask
add constraint FKrqtooosvfj0qtdol7arw1ur71
foreign key (task_id)
references Task;
How can this be done?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…