title: JPA how to join these entities
body: <p>Given the JPA entities below, I want to get <strong>all Debits which has a Request with at least one succesful status.</strong></p>
  
  <p>There can be many requests with the same debit_id and different statuses</p>
  
  <p>Should I use something like this or there is a better way of doing things</p>
  
  <p><em>entityManager.createQuery( "select c from Debit d join d.id where request.status =Succesful"</em></p>
  
  <pre><code>@Entity(name = "T_DEBIT")
  public class Debit {
    public enum Status { NEW, OLD } 
  
    @Column(name = "STATUS", nullable = false, length = 20)
    @Enumerated(value = EnumType.STRING)
    private Status status;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private Long id;
  
    @ManyToOne(optional = false)
    @JoinColumn(name = "ACCOUNT_ID", updatable = false, nullable = false)
    private Account account;
  
  }
  </code></pre>
  
  <p>and other entity is</p>
  
  <pre><code>@Entity(name = "T_REQUEST")
  public class Request{  
  
    public enum Status { PENDING, FAILED, SUCCESFUL}  
  
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private Long id;
  
    @ManyToOne(optional = false)
    @JoinColumn(name = "DEBIT_ID", updatable = false, nullable = false)
    private Debit debit;
  
    @Column(name = "STATUS", nullable = false, length = 20)
    @Enumerated(value = EnumType.STRING)
    private Status status;
  
   }
  </code></pre>
  
  <p>Please do comment if anything is missing instead of closing or downvoting the question!</p>