Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [select count(*) from com.test.Fruits as fruit where fruit.fruitId in () order by fruit.fruitName desc ]
02
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
03
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
04
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
05
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
06
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
07
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
08
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
09
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
10
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
11
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
12
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1113)
13
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
14
at com.test.FruitDAOServiceImpl.fruitCount(FruitDAOServiceImpl.java:682)
15
at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
16
at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
17
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
18
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
19
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
20
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)</code>
While there could be many reasons because of which this error comes. For me, the problem was that the parameter list I was passing was empty.
I was getting all the fruits for which fruit id is in the fruitIdList I was passing as the query parameter. If the fruitIdList is emply list then this problem comes. I solved it by conditionally framing query based on the list. That is instead of
Query fruitQuery = getSession().createQuery("select count(*) from com.test.Fruits as fruit where fruit.fruitId in (:fruitIdList) order by fruit.fruitName desc ");
Hibernate error : org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree
Update: Look at the comments for more information and possible solutions. I got this error today.view sourceprint?01Caused by: org.hibernate.hql.ast.QuerySyntaxException: