title: java hibernate aggregation error
body: <pre><code>qty|price
  1 | 4
  4 | 5
  6 | 4
  2 | 3
  1 | 2
  </code></pre>
  
  <p>are entries on the database. i am trying to get the result: (group quantity by price)</p>
  
  <pre><code>qty|price
  7 | 4
  4 | 5
  2 | 3
  1 | 2
  </code></pre>
  
  <p>I am successful when i do this query using sqlwave to my local databse</p>
  
  <blockquote>
    <p>SELECT price, sum(quantity) FROM table</p>
  </blockquote>
  
  <p>but when I try this in java/hibernate.. and try to list, i don't get the results for sum() aggregation. i tried aggregation.. but it gives me the sum of all the quantities instead of by price. How do i restrict so I get the sum of the quantity for specific price??</p>
  
  <p>Here's my method:</p>
  
  <pre><code>protected void listInventory(String productID)
  {
  Session session = sessionFactory.openSession();
  Transaction tx = null;
  try{
  tx = session.beginTransaction();
  
  Query query = session.createQuery("SELECT price, sum(quantity) FROM table WHERE product_code=:productID GROUP BY price");
  
  query.setParameter("product_code",productID);
  
  List iv = query.list();
  for(Iterator iterator = iv.iterator();iterator.hasNext();){
  Products pb = (Products)iterator.next();
  System.out.println("Price: "+pb.getPrice());
  System.out.println("Quantity: " + pb.getQuantity());
  }
  tx.commit();
  }catch (HibernateException e) {
         if (tx!=null) tx.rollback();
         e.printStackTrace(); 
      }finally {
             session.close();serverWriter.flush(); 
          }
  }
  </code></pre>