title: Spring Boot JPA OneToMany and ManyToOne bring me all registers in JoinTable
body: <p>Hi im using JPA and i need to use OneToMany and ManyToOne, it works well with one register but when i insert more than one register the result contains all data registered in jointable.</p>
  <p>Example:</p>
  <p>I have the following tables, <strong>User</strong> and <strong>Company</strong>, and Join table  <strong>USER_COMPANY_REL</strong></p>
  <p>Table User</p>
  <pre><code>USER_ID
  NAME
  ADDRESS
  ...
  </code></pre>
  <p>Table Company</p>
  <pre><code>COMPANY_ID
  NAME
  WEB_SITE
  ...
  </code></pre>
  <p>USER_COMPANY_REL</p>
  <pre><code>REL_ID
  USER_ID
  COMPANY_ID
  </code></pre>
  <p>I have Data of 3 Users and 2 Companies,  if i have in my USER_COMPANY_REL table one user with one company, it works, if i put the same user with another comany it works, but when i put another user with another company, when i get Data from some user (with one or more companies registered) the result is: User info plus as many companies as are registered in Join table.</p>
  <p>I have this in my  Spring Boot code</p>
  <p>Class COMPANY</p>
  <pre><code>...
   @ManyToOne
        @JoinTable(name = &quot;USER_COMPANY_REL&quot;,
                joinColumns = {@JoinColumn(name = &quot;COMPANY_ID&quot;, insertable = false,
                        updatable = false, referencedColumnName = &quot;COMPANY_ID&quot;)},
                inverseJoinColumns = {@JoinColumn(name = &quot;USER_ID&quot;, insertable = false,
                        updatable = false, referencedColumnName = &quot;USER_ID&quot;)}
        )
      private User user;
  ...
  </code></pre>
  <p>Class USER</p>
  <pre><code>...
  @OneToMany
        @JoinTable(name = &quot;USER_COMPANY_REL&quot;,
                joinColumns = {@JoinColumn(name = &quot;USER_ID&quot;, referencedColumnName = &quot;USER_ID&quot;)},
                inverseJoinColumns = {@JoinColumn(name = &quot;COMPANY_ID&quot;, referencedColumnName = &quot;COMPANY_ID&quot;)}
        )
  ...
  </code></pre>
  <p>And this is postman result
  <a href="https://i.stack.imgur.com/s1Jdh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s1Jdh.png" alt="enter image description here" /></a></p>
  <p>Why is this happening? can you help me?</p>
  <p>Regards</p>