Я имею проблемы с выполнением запроса HQL, как это:Простые трудности с HQL Query
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 для правильного синтаксиса, чтобы использовать вблизи «.datx.web.accounting.view.CoverDocumentReportView (Re.code AS fulCd, Re.creditP» в строке 1
2) Если я исполню ее с этим:
Query query = session.createQuery(sql).setResultTransformer(Transformers.aliasToBean(CoverDocumentReportView.class));
ArrayList<CoverDocumentReportView> li = (ArrayList<CoverDocumentReportView>)query.list();
ошибка будет:
ER ROR 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: неожиданный токен: сумма
В чем проблема?
Возможно, вы захотите увидеть здесь http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html –
Кстати, с учетом регистра не было проблем. –