why hibernate creates a join table for unidirectional OneToMany?

后端 未结 2 1597
太阳男子
太阳男子 2021-01-01 19:44

Why hibernate uses a join table for these classes?

@Entity
public class CompanyImpl {
    @OneToMany
    private Set flights;


@Entity
public          


        
2条回答
  •  灰色年华
    2021-01-01 19:57

    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 flights;
    }
    

    This is documented.

提交回复
热议问题