Hibernate: Why is binding for a field similar weather explicit @JoinColum annotation is used or not?

孤街醉人 提交于 2019-12-04 16:44:11

Is @JoinColum implicitly specified when we use any association type annotation like @OneToOne, @OneToMany, etc.

The answer is: NO. Except the case when mappedBy is used.

When you specify @JoinColumn or mappedBy (even without @JoinColumn) Hibernate implies that you want to use an association via a foreign key (without a join table).

When you don't specify @JoinColumn Hibernate uses a join table and creates it for you — student_laptops in your case.

You can add a @JoinTable annotation to stress the fact that you are using a jon table.

@OneToMany(cascade = CascadeType.ALL)
@JoinTable
private List<Laptop> laptops = new ArrayList<Laptop>();  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!