@ManyToMany/@OneToMany mappedby attribute for bidirectional association

时光怂恿深爱的人放手 提交于 2019-12-01 12:54:38

This is far from being a corner case. Every bidirectional association has an owner side and an inverse side.

JPA uses the owning side to decide if an association exists between two entities. The other side is ignored.

The owning side is the one which defines how the association is mapped (using the JoinColumn, JoinTable, etc. annotations). It doesn't have any mappedBy attribute.

The inverse side uses the mappedBy attribute to say: "Hey, I'm just the inverse association of the one mapped by the following property".

So, by definition, the owning side doesn't have a mappedBy attribute. If it had one, it wouldn't be the owning side.

This is well explained in the JPA spec. If you need to build a compliancy kit for this specification, you'd better read and understand it.

I don't really see the point of writing such a compliancy kit since, as written on the JPA2 JSR home page,

As required by the Java Specification Participation Agreement (JSPA), the Java Persistence API, version 2.0 TCK will be licensed at no charge without support to qualified not-for-profit entities. Such qualification will be verified by the Compatibility Testing Scholarship Program. Support may also be provided at no charge with approval of the scholarship board. For more information, please refer to: http://java.sun.com/scholarship/.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!