title: How to retrieve all primary keys of a table using hibernate?
body: <p>I need to retrieve all primary keys of a table and put them in a list.
  Any method that I have found so far let me retrieve each record as an object, which force me to retrieve their primary keys separately and add them to the list.</p>
  
  <p>Is there any other approach to retrieve the primary keys of a table and adding them to a list?</p>
  
  <p>Using the following code hibernate returns objects but I need it to return a list of primary keys to store them in pk list.</p>
  
  <pre><code>            List pk = new ArrayList():
              Criteria criteria = session.createCriteria(MyTable.class, "mytable");
              pk = criteria.list();
  </code></pre>
  
  <p>if mytable is as following </p>
  
  <pre><code>id name value
  1  a      z4
  2  f      o2
  </code></pre>
  
  <p>pk list should be </p>
  
  <pre><code>[1,2]
  </code></pre>