title: JPQL Left Join - how to set up entity relationship in entity classes
body: <p>Two tables:</p>
  
  <pre><code>TABLE_1:
  REC_ID
  1
  2
  3
  4
  
  TABLE_2:
  REC_ID REC_VAL
  2      A
  3      B
  </code></pre>
  
  <p>Entity classes (basic structure):</p>
  
  <pre><code>@Entity
  @Table(name="TABLE_1")
  public class Entity1 {
      @Id
      @Column(name="REC_ID")
      private String recId;
  
      //getters and setters
  }
  
  @Entity
  @Table(name="TABLE_2")
  public class Entity2 {
      @Id
      @Column(name="REC_ID")
      private String recId;
  
      @Column(name="REC_VAL")
      private String recVal;
  
      //getters and setters
  }
  </code></pre>
  
  <p>SQL Query and result:</p>
  
  <pre><code>SELECT T1.REC_ID, T2.REC_VAL FROM TABLE_1 T1 LEFT OUTER JOIN TABLE_2 T2 ON T1.REC_ID = T2.RED_ID
  
  Result:
  REC_ID REC_VAL
  1      null
  2      A
  3      B
  4      null
  </code></pre>
  
  <p>JPQL Query:</p>
  
  <pre><code>SELECT e1.recId, e2.recVal FROM Entity1 e1 LEFT JOIN e1.&lt;an Entity2 field in Entity1*&gt;
  </code></pre>
  
  <p>* I know I don't have it in the given structure above, but I want to know how to do it right. And how do I choose from @ManyToOne, @OneToOne, etc.</p>
  
  <p><strong>How do I modify the Entity classes and the JPQL query to achieve the same result as the SQL query?</strong> I've been trying various things, nothing works. It wouldn't allow me to create two fields with the same column name, or to define the String as the @JoinColumn. I almost got it working, but the generated SQL query contains a reference to REC_ID_REC_ID column in TABLE_2 which doesn't exist. And after Googling so much, I can't find a proper guide for this (<em>ignoring that JPQL does not support in-line join conditions!</em>)</p>