Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have three classes:

  • PlanItem
  • Task
  • SubTask

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
264 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...