title: Some basic questions on Criteria from JPA 2.0
body: <p>I discovered JPA 2.0 Criteria API today and want to learn it. Just went through some examples and try to do a hands on. I have a table fruit with columns:</p>
  
  <ul>
  <li>id, </li>
  <li>name, </li>
  <li>color, </li>
  <li>size, </li>
  <li>taste.</li>
  </ul>
  
  <p>The regular stuff:</p>
  
  <pre><code>EntityManagerFactory emf = Persistence.createEntityManagerFactory("fruitManager");
  EntityManager em = emf.createEntityManager();
  
  //get the criteria builder
  CriteriaBuilder cb = em.getCriteriaBuilder();
  
  CriteriaQuery&lt;Fruit&gt; c = cb.createQuery(Fruit.class);
  </code></pre>
  
  <ol>
  <li><p>How will the following query get built using criteria:</p>
  
  <pre><code>select id, name, color where name like 'XY%' and  color='orange'
  </code></pre>
  
  <p>I.e. how to:</p>
  
  <ul>
  <li>fetch only some columns,</li>
  <li>include wild card search,</li>
  <li>include AND, OR where conditions.<br>
  <br />  </li>
  </ul></li>
  <li>Also, its always better to get count of the result first before fetching the actual data.  How can I fetch the result count first?</li>
  </ol>
  
  <p>Also Is there any place where I can get more examples on 'Criteria' with several different kinds of SQL queries?</p>