Hibernate-在没有相关表的情况下引用OneToMany

时间:2019-08-18 11:02:27

标签: java hibernate jpa orm ddl

我有以下映射。工作正常。问题在于Hibernate为此创建了3个表:requestresearchrequest_researches
不需要request_researches
我希望外键位于research表中。 (research.request_id

@Entity
public class Request{

    @Id
    private Long id;

    @OneToMany(targetEntity = Research.class,cascade= CascadeType.ALL, fetch = FetchType.EAGER)
    private List<ResearchEntity> researches = new ArrayList<>();

    //... getters setters
}

这可能吗?

谢谢

1 个答案:

答案 0 :(得分:1)

只需添加一个@JoinColumn批注,即可从相关实体中指定列:

    @OneToMany(targetEntity = Research.class,cascade= CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "request_id")
    private List<ResearchEntity> researches = new ArrayList<>();