我有这个Java代码(JPA):
String queryString = "SELECT b , sum(v.votedPoints) as votedPoint " + " FROM Bookmarks b " + " LEFT OUTER JOIN Votes v " + " on (v.organizationId = b.organizationId) " + "WHERE b.userId = 101 " + "GROUP BY b.organizationId " + "ORDER BY votedPoint ascending "; EntityManager em = getEntityManager(); Query query = em.createQuery(queryString); query.setFirstResult(start); query.setMaxResults(numRecords); List results = query.getResultList();
我不知道我的查询有什么问题,因为它给了我这个错误:
java.lang.NoSuchMethodError: org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)V at org.hibernate.hql.antlr.HqlBaseParser.fromJoin(HqlBaseParser.java:1802) at org.hibernate.hql.antlr.HqlBaseParser.fromClause(HqlBaseParser.java:1420) at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1130) at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:702) at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296) at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159) at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:271) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
谢谢.
您使用的hibernate和ANTLR jar版本肯定存在问题.在版本2.7.6之前,ANTLR Parser类中没有恢复方法?如果您使用的是早期版本的ANTLR,例如2.7.2,那么您将看到此问题.
使用maven会导致这种情况,你依赖于Hibernate及其传递依赖,但是"更接近"; 例如Struts; 提供者ANTLR的早期版本不同,早期版本在您的应用程序中得到解决.
如果您能提供所涉及的罐子的版本,我们将能够提供更多帮助.一旦你修复了jar版本的问题,你应该得到一个更具启发性的错误信息,它显示你的HQL表达式有什么问题.