How is the “Owning Side” of this many-to-many relationship determined?

后端 未结 3 1742
天命终不由人
天命终不由人 2021-02-07 23:54

I\'m trying to get a firm grasp on the concept of Owning-side. Couldn\'t really get a clear picture from any question i found here. Basically I\'m going through the Java EE JPA

相关标签:
3条回答
  • 2021-02-08 00:24

    AFAIK you get to determine the owning side. There is nothing wrong in choosing any particular side in a m:n scenario.

    So, to answer your questions:

    1. How is it determined that TEAM is the owning side?

    Arbitrarily I think.

    2 . Would it make any difference if PLAYER was made the owning side instead, in this scenario?

    There will not be any difference

    3 . Would the above statement make my second question true? Meaning that there is no determining factor besides which one you decide to make the owning side, with the @JoinTable annotation?

    Yes

    0 讨论(0)
  • 2021-02-08 00:32
    1. How is it determined that TEAM is the owning side?

    In the case of ManytoMany relationships in bidirectional scenario the Owner of the relationship can be selected arbitrarily, but having in mind the purpose you should select the entity that makes more sense to retrieve first or the one that is more used according to your purpose. You only need to remember that Many always need to be the owning side in ManyToOne scenarios.

    1. Would it make any difference if PLAYER was made the owning side instead, in this scenario?

    No, it wouldn´t as the relationship is bidirectional.

    1. Would the above statement make my second question true? Meaning that there is no determining factor besides which one you decide to make the owning side, with the @JoinTable annotation?

    Yes, @JoinTable must to be in the owner in the relationship as some other annotations. Once you select the owner you should add the annotation in that class.

    Consider also the Cascade operation you need to have if apply, and if there are need to be in both side of the relationship.

    0 讨论(0)
  • 2021-02-08 00:36

    According to your question, you use ManyToMany relationship bidirectional.Here is my answer,

    For question 1

    • According to the database design,it is determined TEAM is ownerside.

    For question 2

    • There is no difference if PLAYER was made the owning side instead, in this scenario.See this documentation.

    For question 3

    1. It depend on your database design.
    0 讨论(0)
提交回复
热议问题