title: How to map Join table as Entity JPA
body: <p>In my system, I have <code>User</code> and <code>User</code> can be a <code>Manager</code> or a client or even bought. <code>Manager</code> can have many <code>Clients</code> and <code>Client</code> can have many managers. <code>Manager</code> is represented by <code>manager_id</code> in <code>managers_clients</code>, so if <code>User</code> is a manager we will store his id to that column. And the same goes for the client.</p>
  <p>My database tables look like this:</p>
  <pre><code>users (table)
  UUID  FIRST_NAME   LAST_NAME
  1   Bob     Way
  2   Sarah   Smith
  
  managers_clients (table)
  ID  MANAGER_ID CLIENT_ID
  1   1          1
  2   1          2 
  </code></pre>
  <p>Now here <code>MANAGER_ID</code> and <code>CLIENT_ID</code> are reference to <code>users.id</code></p>
  <p>I know that is possible to create a 3rd entity <code>Manager</code> and tie them up with this pivot table... But I'm trying to achieve without it.</p>
  <p>My current entities look like this:</p>
  <pre><code>public class UserEntity {
  
    @Id
    @GeneratedValue(strategy = AUTO)
    private UUID uuid;
  
    @Column(name = &quot;first_name&quot;)
    private String firstName;
  
    @Column(name = &quot;last_name&quot;)
    private String lastName;
  
    @OneToMany
    private List&lt;ManagerClientEntity&gt; managers;
  
    @OneToMany
    private List&lt;ManagerClientEntity&gt; clients;
  }
  
  public class ManagerClientEntity {
  
    @Id
    @GeneratedValue(strategy = AUTO)
    private UUID uuid;
  
    @ManyToOne
    private UserEntity manager;
  
    @ManyToOne
    private UserEntity client;
  }
  </code></pre>
  <p>But, of course, it doesn't work...</p>
  <p>I`m new to JPA and Java, so can't figure out how should I map my entities?</p>