次のような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-2214:16:19,838 [http-8080-1] org.hibernate.util.JDBCExceptionReporter:SQL構文にエラーがあります。1行目の'.datx.web.accounting.view.CoverDocumentReportView(Re.code AS fulCd、Re.creditP'の近くで使用する正しい構文については、MySQLサーバーのバージョンに対応するマニュアルを確認してください。
2) これで実行した場合:
Query query = session.createQuery(sql).setResultTransformer(Transformers.aliasToBean(CoverDocumentReportView.class));
ArrayList<CoverDocumentReportView> li = (ArrayList<CoverDocumentReportView>)query.list();
エラーは次のようになります。
エラー2012-12-2214: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行目:予期しないトークン:合計
何が問題ですか?