OneToMany UNI可以使用JoinColumn吗?

时间:2018-01-06 12:31:12

标签: java jpa

我使用JoinColumn进行以下OneToMany UNI映射:

enter image description here

但在JPA wikibooks我读到这是错误的,如果是JoinColumn,则需要反向关系。我不明白为什么。我的代码有效。捕获的地方在哪里?

If the OneToMany uses a foreign key in the target object's table JPA requires that the
relationship be bi-directional (inverse ManyToOne relationship must be defined 
in the target object), and the source object must use the mappedBy 
attribute to define the mapping.

1 个答案:

答案 0 :(得分:0)

@OneToMany上的@JoinColumn在JPA 2.0中引入之前无法实现。

效果提示:

根据Hibernate提交者Vlad Mihalcea的说法,最好使用双向实现: https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/