I have the following OneToMany UNI mapping with JoinColumn:
But in JPA wikibooks I read this is wrong and in case of JoinColumn an inverse relationship is required. 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.
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/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.