I need help with this error: java.lang.NoSuchMethodError

Ionut picture Ionut · Nov 21, 2008 · Viewed 13.4k times · Source

I have this Java code (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();

I don't know what is wrong with my query because it gives me this error:

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)

Thanks.

Answer

jabley picture jabley · Jan 7, 2009

You definitely have an issue with the version of hibernate and ANTLR jars that you are using. The recover method wasn't present in the ANTLR Parser class until version 2.7.6? If you are using an earlier version of ANTLR, such as 2.7.2, then you will see this problem.

Using maven can cause this sort of situation, where you depend on Hibernate and its transitive dependencies, but something 'closer'; e.g. Struts; providers a different, earlier version of ANTLR and that earlier version gets resolved in your application.

If you can provide the version of jars involved, we would be able to help some more. Once you have fixed the issue with the jar versions, you should get a more revealing error message which shows what is wrong with your HQL expression.