org.hibernate.hql.internal.ast.ErrorCounter:意外令牌:(

时间:2014-10-27 12:05:11

标签: java sql hibernate hql jpa-2.0

当我尝试执行以下查询时,我收到以下错误 -

错误

ERROR [2014-10-27 11:17:24,264] org.hibernate.hql.internal.ast.ErrorCounter: line 1:33: unexpected token: (
ERROR [2014-10-27 11:17:24,304] org.hibernate.hql.internal.ast.ErrorCounter: line 1:33: unexpected token: (
! antlr.NoViableAltException: unexpected token: (

ERROR [2014-10-27 11:17:24,306] org.hibernate.hql.internal.ast.ErrorCounter: line 1:68: unexpected token: MAX
ERROR [2014-10-27 11:17:24,312] org.hibernate.hql.internal.ast.ErrorCounter: line 1:68: unexpected token: MAX
! antlr.NoViableAltException: unexpected token: MAX  

查询

String sSubQuery =  "SELECT om.path, om.originalSize, MAX(om.lastModified) "+
                    "FROM "+
                    "ObjectMetadata om "+
                    "WHERE om.informationStoreId = '"+informationStoreDefinitionID+"' "+
                    "GROUP BY om.path, om.originalSize";

             String sQuery =  "SELECT SUM(o.originalSize) "+
                    "FROM "+
                    "("+
                    " "+sSubQuery+
                    " ) "+
                    "o";

            Query q = getEm().createQuery(sQuery);

请帮助。

1 个答案:

答案 0 :(得分:1)

尝试

String sSubQuery = "SELECT SUM(om.originalSize), MAX(om.lastModified) "+ 
                   "FROM "+ "ObjectMetadata om "+ 
                   "WHERE om.informationStoreId = :informationStoreDefinitionID "+ 
                   "GROUP BY om.path, om.originalSize";

Query q = getEm().createQuery(sQuery);
q.addParameter("informationStoreDefinitionID",22);