title: HQL with multiple tables joining and sum(), first()
body: <p>Talbes:</p>
  
  <pre><code>Grandpa
      GP_ID  (PK)
      NAME
  
  Dad
      DAD_ID (PK)
      PG_ID  (FK)
  
  Children
      C_ID   (PK)
      DAD_ID (FK)
      MONEY_AMOUNT
      MONEY_UNIT
  </code></pre>
  
  <p>Class (annotations omitted here):</p>
  
  <pre><code>class Grandpa
  {
      Long id;
      String name;
  
      Double moneyAmount; // sum of Children's money amount
  
      String moneyUnit; // first of Children's money unit.
  }
  
  class Dad
  {
      Long id;
      Grandpa grandpa;
  }
  
  class Children
  {
      Long id;
      Dad dad;
  
      Double moneyAmount;
      String moneyUni;
  }
  </code></pre>
  
  <p>I want to write a hql to get the Grandpa objects with sum(grandpa.dad.children.money_amount) and first(grandpa.dad.children.money_unit). Here is mine but it doesn't work:</p>
  
  <pre><code>select gp, sum(chdn.moneyAmount) as gp.moneyAmount, first(chdn.moneyUnit) as gp.moneyUnit
  from Grandpa gp, Dad dad, Children chdn
  where gp.id =: chdn.dad.grandpa.id
  </code></pre>