JPA: which side should be the owning side in a m:n relationship?

后端 未结 6 1959
予麋鹿
予麋鹿 2020-12-30 08:12

Say, for example, I had two entities: Article and Tag (like in a typical blog). Each article can have many tags, and each tag can be used by many a

6条回答
  •  星月不相逢
    2020-12-30 08:28

    Every bidirectional relationship requires an owning side in JPA. In the particular case of ManyToMany:

    • @JoinTable is specified on the owning side of the relationship.
      • the owning side is arbitrary, you can pick any of the two entities to be the owner.

    From the JPA specification:

    9.1.26 ManyToMany Annotation

    Every many-to-many association has two sides, the owning side and the non-owning, or inverse, side. The join table is specified on the owning side. If the association is bidirectional, either side may be designated as the owning side.

提交回复
热议问题