title: Simple difficulty with HQL Query
body: <p>I am having a trouble with executing an HQL query like this:</p>
  
  <pre><code>select new myPackage.view.CoverDocumentReportView(Re.code AS fulCd,
  Re.creditPrice AS crtprc,
  Re.debitPrice  AS dbtprc,
  (Re.debitPrice - Re.debitPrice) AS redbtprc,
  (Re.creditPrice- Re.creditPrice) AS recrtprc,
  (Re.debitPrice-Re.creditPrice)   AS rem) 
  from 
  (select  fullCode as code, 
       sum(creditPrice) as creditPrice ,
       sum(debitPrice)  as debitPrice   
  from    DocumentMaster DM,
       DocumentAccount   DA,
       Tree              T ,
       AccountTree       AT, 
       DocumentDetailed  DD 
  where DM.id =  DA.documentMaster  and  
        DA.accountTree =  T.id      and   
        DA.accountTree =  AT.id     and   
        DD.documentAccount =  DA.id 
  group by  DA.accountTree ) As Re
  </code></pre>
  
  <p><hr>
  <strong>1)</strong>
  If I execute this like:</p>
  
  <pre><code>SQLQuery crit = (SQLQuery) session
              .createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(CoverDocumentReportView.class));
  ArrayList&lt;CoverDocumentReportView&gt; li =  (ArrayList&lt;CoverDocumentReportView&gt;) crit.list();
  </code></pre>
  
  <blockquote>
    <p>ERROR 2012-12-22 14:16:19,838 [http-8080-1] org.hibernate.util.JDBCExceptionReporter : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.datx.web.accounting.view.CoverDocumentReportView(Re.code AS fulCd,
      Re.creditP' at line 1</p>
  </blockquote>
  
  <p><hr>
  <strong>2)</strong>
  If I execute it with this:</p>
  
  <pre><code>Query query = session.createQuery(sql).setResultTransformer(Transformers.aliasToBean(CoverDocumentReportView.class));
  ArrayList&lt;CoverDocumentReportView&gt; li =  (ArrayList&lt;CoverDocumentReportView&gt;)query.list();
  </code></pre>
  
  <p>The error will be:</p>
  
  <blockquote>
    <p>ERROR 2012-12-22 14:51:46,709 [http-8080-1] org.hibernate.hql.ast.ErrorCounter : line 1:224: unexpected token: (
    ERROR 2012-12-22 14:51:46,709 [http-8080-1] org.hibernate.hql.ast.ErrorCounter : line 1:308: unexpected token: sum</p>
  </blockquote>
  
  <p>What is the problem?</p>