[英]Is OneToMany UNI with JoinColumn possible?
I have the following OneToMany UNI mapping with JoinColumn: 我有以下与JoinColumn的OneToMany UNI映射:
But in JPA wikibooks I read this is wrong and in case of JoinColumn an inverse relationship is required. 但是在JPA Wikibooks中,我读到这是错误的,如果使用JoinColumn,则需要反向关系。 I can't understand why.
我不明白为什么。 My code works.
我的代码有效。 Where's the catch?
哪里有收获?
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.
@JoinColumn on @OneToMany was introduce in JPA 2.0 before this was not possible. 在JPA 2.0中,@ OneToMany上的@JoinColumn是不可能的。
Performance tip: 性能提示:
According to the Hibernate commiter Vlad Mihalcea it's better to use a bi-directional realtionship: https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/ 根据Hibernate的提交人Vlad Mihalcea的说法,最好使用双向代理: https ://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.