为什么hibernate为单向OneToMany创建一个连接表?

编程入门 行业动态 更新时间:2024-10-14 08:22:09
本文介绍了为什么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创建一个连接表?

本文发布于:2023-10-23 05:24:37,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   hibernate   OneToMany

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!