org.hibernate.hql.internal.ast.ErrorCounter:意想不到的令牌:

时间:2021-09-17 05:08:25

I am getting the following Error When I try to execute the below query-

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

Error

错误

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  

Query

查询

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);

Please Help.

请帮助。

1 个解决方案

#1


1  

Try

试一试

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);

#1


1  

Try

试一试

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);