title: convert nested sql query to jpa/hibernate
body: <p>We use jpa/hibernate, but we have some native query like this one.</p>
  
  <pre><code>  SELECT cp1.id AS customerbookid
    FROM customerbook cp1
    INNER JOIN customer cu ON cu.id = cp1.customerid
    WHERE cp1.autoRenew='Y'
      AND cp1.endTime &lt; now()
  AND
    (SELECT cp2.customerid
    FROM customerbook cp2
    WHERE cp1.customerid=cp2.customerid
      AND cp2.startTime &gt; now() 
    ) IS NULL
  </code></pre>
  
  <p>mapping</p>
  
  <pre><code>  @Entity
    @Table(name = "customerbook")
    public class CustomerBook{
  
  @Id
  @Column(name = "id")
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  
  @Column(name = "customerId")
  private long customerId;
  
  @Column(name = "startTime")
  private Timestamp startTime;
  
  @Column(name = "endTime")
  private Timestamp endTime;
  
  @Column(name = "autoRenew")
  private Character autoRenew;
    }
  
    @Entity
    @Table(name = "customer")
    public class customer{
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    }
  </code></pre>
  
  <p>Is it possible to convert it to jpa?</p>