我在执行这样的 HQL 查询时遇到问题:
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
1) 如果我这样执行:
SQLQuery crit = (SQLQuery) session
.createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(CoverDocumentReportView.class));
ArrayList<CoverDocumentReportView> li = (ArrayList<CoverDocumentReportView>) crit.list();
错误 2012-12-22 14:16:19,838 [http-8080-1] org.hibernate.util.JDBCExceptionReporter:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '.datx.web.accounting.view.CoverDocumentReportView(Re.code AS fulCd, Re.creditP' 附近使用正确的语法
2) 如果我用这个执行它:
Query query = session.createQuery(sql).setResultTransformer(Transformers.aliasToBean(CoverDocumentReportView.class));
ArrayList<CoverDocumentReportView> li = (ArrayList<CoverDocumentReportView>)query.list();
错误将是:
错误 2012-12-22 14:51:46,709 [http-8080-1] org.hibernate.hql.ast.ErrorCounter:第 1:224 行:意外令牌:(错误 2012-12-22 14:51:46,709 [http -8080-1] org.hibernate.hql.ast.ErrorCounter:第 1:308 行:意外令牌:总和
问题是什么?