title: Right join using JPA criteria api
body: <p>I'm trying to implement this sql query using jpa criteria api :</p>
  
  <pre><code>SELECT F.* FROM PF right join F on F.FID = PF.FID WHERE PF.PFID is null;
  </code></pre>
  
  <p>Which also can be written as:</p>
  
  <pre><code>SELECT F.* FROM F left join PF on F.FID = PF.FID WHERE PF.FID is null;
  </code></pre>
  
  <p>This is what I tried:</p>
  
  <pre><code>public List&lt;F&gt; listFWithoutP() {
      final CriteriaBuilder builder = getCriteriaBuilder();
      final CriteriaQuery&lt;F&gt; query = builder.createQuery(F.class);
      final Root&lt;PF&gt; from = query.from(PF.class);
  
      Join&lt;PF, F&gt; join = from.join(PF_.f, JoinType.RIGHT);
  
      query.select(join.get(PF_.f))
              .where(builder.isNull(from.get(PF_.pFId)));
  
      final TypedQuery&lt;F&gt; typedQuery = getEntityManager().createQuery(query);
      return typedQuery.getResultList();
  }
  </code></pre>
  
  <p>But it doesn't work, I get the following error in this line : <code>query.select(join.get(PF_.f))</code></p>
  
  <pre><code>The method get(SingularAttribute&lt;? super F,Y&gt;) in the type Path&lt;F&gt; is not applicable for the arguments (SingularAttribute&lt;PF,F&gt;)
  </code></pre>
  
  <p>How can I solve this ?</p>
  
  <h1>Update:</h1>
  
  <p>These are my entities :</p>
  
  <pre><code>    public class F extends AbstractDomain&lt;Long&gt; {
  
          @Id
          @Column
          @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idgen")
          private Long fId;
  
          @Column(nullable = false)
          private String lib;
      }
  
  public class PF extends AbstractDomain&lt;Long&gt; {
  
      @Id
      @Column
      private Long pFId;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(nullable = false)
      private P p;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(nullable = false)
      private F f;
  }
  </code></pre>
  
  <h1>Update 2:</h1>
  
  <p>It seems like RIGHT JOIN is not supported by the jpa criteria api, so this can be done using the second query.</p>