title: JPA 2 CriteriaQuery Question
body: <p>I am just starting out with JPA 2 criteria query API and finding it tough to learn. Looked around the net a bit, but haven't found good examples/tutorials yet. Can someone suggest a good tutorial and/or help me with the following simple query I am trying to code?</p>
  
  <p>I have a class called Transaction that has a reference to the Account that it belongs:</p>
  
  <pre><code>public class Transaction {
      private Account account;
      ...
  }
  
  public class Account {
      private Long id;
      ...
  }
  </code></pre>
  
  <p>I need to code a query that gets all the transactions for an account given its account id. Here's my attempt at doing this (which obviously doesn't work):</p>
  
  <pre><code>public List&lt;Transaction&gt; findTransactions(Long accountId) {        
      CriteriaBuilder builder = entityManager.getCriteriaBuilder();
      CriteriaQuery&lt;Transaction&gt; query = builder.createQuery(Transaction.class);
      Root&lt;Transaction&gt; transaction = query.from(Transaction.class);
  
      // Don't know if I can do "account.id" here
      query.where(builder.equal(transaction.get("account.id"), accountId));
      return entityManager.createQuery(query).getResultList();
  }
  </code></pre>
  
  <p>Can someone point me in the right direction? </p>
  
  <p>Thanks.
  Naresh</p>