本文介绍了为什么hibernate为单向OneToMany创建一个连接表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么hibernate为这些类使用连接表? @Entity public class CompanyImpl { @OneToMany 私人设置< Flight>航班; @实体公共类航班{
我不想要一个连接表和一个双向关联:($ / b>
解决方案因为这就是它的设计方式, JPA规范告诉它映射这样一个关联,如果你想在Flight表中使用一个连接列,使用
@Entity public class CompanyImpl { @OneToMany @JoinColumn(name =company_id) private设置< Flight>航班; }记录在案。
Why hibernate uses a join table for these classes?
@Entity public class CompanyImpl { @OneToMany private Set<Flight> flights; @Entity public class Flight {I don't want neither a join table nor a bidirectional association:(
解决方案Because that's how it's designed, and what the JPA spec tells it to map such an association. If you want a join column in the Flight table, use
@Entity public class CompanyImpl { @OneToMany @JoinColumn(name = "company_id") private Set<Flight> flights; }This is documented.
更多推荐
为什么hibernate为单向OneToMany创建一个连接表?
发布评论