title: How to use @JsonManagedReference and @JsonBackReference for Many to Many relationship with best practice?
body: <p>I will be much apprecaite for you to explain my questions.</p>
  <p>I have 2 entity and 1 bridge table entity,</p>
  <p>Let's say they are <strong>Team, User and TeamUser.</strong></p>
  <p>TeamEntity:</p>
  <pre><code>    @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = &quot;TEAM_ID&quot;)
      private Integer id;
  
      @JsonManagedReference
      @OneToMany(mappedBy = &quot;team&quot;, cascade = CascadeType.ALL, orphanRemoval = true)
      private Set&lt;TeamUsers&gt; team_users = new HashSet&lt;&gt;();
  </code></pre>
  <p>UserEntity:</p>
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Integer id;
  
  @JsonBackReference
  @OneToMany(mappedBy = &quot;user&quot;)
  private Set&lt;TeamUsers&gt; team_users = new HashSet&lt;&gt;();
  </code></pre>
  <p>TeamUserEntity(bridge table):
  @EmbeddedId
  private TeamUsersId id;</p>
  <pre><code>@ManyToOne
  @MapsId(&quot;teamId&quot;)
  @JoinColumn(name = &quot;team_id&quot;)
  @JsonBackReference
  private Team team;
  
  @ManyToOne
  @MapsId(&quot;userId&quot;)
  @JoinColumn(name = &quot;user_id&quot;)
  @JsonManagedReference
  private User user;
  
  @Column(name = &quot;active&quot;)
  private int active;
  </code></pre>
  <p>As you can see I used <strong><strong>@JsonManagedReference and @JsonBackReference</strong></strong>
  <em><strong>to telling the program the direction for the query of the Entity and avoid infinite recrusive.</strong></em></p>
  <p>Now if I run get <em><strong>repo.findAll()</strong></em> on <em><strong>Team CRUDrepository</strong></em> I will get all Team object, and within the content I will get all bridge table data and it also include User details information.</p>
  <p>But Let's say sometimes if I want to query the data in oppisite way, I want to get All User information and the object should contain all Team information, looks like the annotation <em><strong>@JsonManagedReference and @JsonBackReference</strong></em> block the result.</p>
  <p>In real world development, how should we manage here?</p>