为什么hibernate为单向OneToMany创建一个连接表? [英] why hibernate creates a join table for unidirectional OneToMany?

查看:125
本文介绍了为什么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创建一个连接表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆