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

南楼画角 提交于 2019-12-01 19:23:15

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.

Stab in the dark - Are you sure you have a consistent set of jars - perhaps you need to get the antlr jar that comes with the hibernate distribution you are using...

I've found the problem: because this is a native query, java classes for this 2 tables must have some special attributes:
in Bookmarks.java class

@OneToMany(mappedBy = "bookmarkId")
private Collection votesCollection;
and in Votes.java class
@JoinColumn(name = "bookmark_id", referencedColumnName = "bookmark_id")
@ManyToOne
[private Bookmarks bookmarkId;

and i have also changed the query to work


tring queryString = "SELECT b, sum(v.votedPoints) " +
                          "FROM Bookmarks b  " +
                          "LEFT OUTER JOIN b.votesCollection v " + 
                          "WHERE b.userId = 101  " + 
                          "GROUP BY b.organizationId " +
                          "ORDER BY sum(v.votedPoints) asc ";

thanks for the help

May be you have some double-quotes " missing or which should be doubled in your HQL.

Illustration here.

Or you miss some simple quotes as illustrated there

The query seems to be invalid unless it's an artifact of formatting.

I think you meant this:

Select b, ...

to be:

Select b.organizationId, ...

??

I have the consistent set of jars because simple queries like this one

"SELECT b  FROM table_name b  WHERE b.userId = 102 " 

are working. I have verified all double quotes and everything is alright.

My database is: mysql, and I use jpa to connect to it. I don't know what is causing the problem. Maybe this type of join, i don't know

Er, isnt your query trying to select b which is a table alias and thats not allowed as far as I know.

I'd probably guess that something is going wrong with your query, because the method HqlBaseParser fails to lookup is called recover(RecognitionException, Bitset). Perhaps this query fails for some reason the other simpler queries don't (and the NoSuchMethod exception is thrown when attempting to recover from that error).

java.lang.NoSuchMethodError: org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)V

Your query is still wrong. Maybe it works with your driver/db but it isn't standard SQL. You should be selecting b.* or b.organizationId.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!