org.hibernate.hql.ast.QuerySyntaxException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Thanks for adding DML support to HQL. Unfortunatly it still contains few bugs: The following HQL statement works nicely: UPDATE Cat c SET c.weight = (SELECT SUM(f.amount) FROM Food f WHERE f.owner = c) Whereas the following slightly modified (and more useful) statement fails with an QuerySyntaxException (unexpected AST node): UPDATE Cat c SET c.weight = c.weight + (SELECT SUM(f.amount) FROM Food f WHERE f.owner = c) Just asked Hibernate to add to the original value. Working arround by issuing: UPDATE Cat c SET c.weight = (SELECT k+weight + SUM(f.amount) FROM Cat k JOIN k.food f WHERE f.owner = c) Is refused by mysql: "You can't specify target table 'Player' for update in FROM clause". Guess this limitation could be worked arround by throwing the subquery result into a temporary table and selecting from this one. Is there a way for creating temporary tables via HQL? Stacktrace of the original QuerySyntaxException: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [...] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583) Caused by: <AST>:0:0: unexpected AST node: query at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1310) at org.hibernate.hql.antlr.HqlSqlBaseWalker.arithmeticExpr(HqlSqlBaseWalker.java:2716) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1276) at org.hibernate.hql.antlr.HqlSqlBaseWalker.newValue(HqlSqlBaseWalker.java:1165) at org.hibernate.hql.antlr.HqlSqlBaseWalker.assignment(HqlSqlBaseWalker.java:1015) at org.hibernate.hql.antlr.HqlSqlBaseWalker.setClause(HqlSqlBaseWalker.java:729) at org.hibernate.hql.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:349) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:237) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218) ... 34 more
    via by Mathias Hasselmann,
  • Thanks for adding DML support to HQL. Unfortunatly it still contains few bugs: The following HQL statement works nicely: UPDATE Cat c SET c.weight = (SELECT SUM(f.amount) FROM Food f WHERE f.owner = c) Whereas the following slightly modified (and more useful) statement fails with an QuerySyntaxException (unexpected AST node): UPDATE Cat c SET c.weight = c.weight + (SELECT SUM(f.amount) FROM Food f WHERE f.owner = c) Just asked Hibernate to add to the original value. Working arround by issuing: UPDATE Cat c SET c.weight = (SELECT k+weight + SUM(f.amount) FROM Cat k JOIN k.food f WHERE f.owner = c) Is refused by mysql: "You can't specify target table 'Player' for update in FROM clause". Guess this limitation could be worked arround by throwing the subquery result into a temporary table and selecting from this one. Is there a way for creating temporary tables via HQL? Stacktrace of the original QuerySyntaxException: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [...] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583) Caused by: <AST>:0:0: unexpected AST node: query at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1310) at org.hibernate.hql.antlr.HqlSqlBaseWalker.arithmeticExpr(HqlSqlBaseWalker.java:2716) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1276) at org.hibernate.hql.antlr.HqlSqlBaseWalker.newValue(HqlSqlBaseWalker.java:1165) at org.hibernate.hql.antlr.HqlSqlBaseWalker.assignment(HqlSqlBaseWalker.java:1015) at org.hibernate.hql.antlr.HqlSqlBaseWalker.setClause(HqlSqlBaseWalker.java:729) at org.hibernate.hql.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:349) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:237) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218) ... 34 more
    via by Mathias Hasselmann,
  • How to use inner join query in hql?
    via Stack Overflow by Akshant poonia
    ,
  • Problem with Hql Update
    via by Sujoy Mukherjee,
  • unexpected token异常 -
    via by Unknown author,
  • db:: 3.65::JVM 1.3.1* crashes on WL 6.1 zz
    via by Unknown author,
  • If you call CriteriaBuilder.function() respectively "ParameterizedFunctionExpression" with two or more arguments you get an IllegalArgumentException. I think the bug is here: protected void renderArguments(StringBuilder buffer, CriteriaQueryCompiler.RenderingContext renderingContext) { for ( Expression argument : argumentExpressions ) { buffer.append( ( (Renderable) argument ).render( renderingContext ) ); } } The arguments are not seperated by comma. Exception: Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 37 [select TO_CHAR(generatedAlias0.date1:param0) from test.server.TestBean as generatedAlias0] at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1166) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1112) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:315) at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:154) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:432) at test.server.TestApp.main(TestApp.java:28) Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 37 [select TO_CHAR(generatedAlias0.date1:param0) from test.server.TestBean as generatedAlias0] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47) at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82) at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98) 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:1760) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:297) ... 3 more Code: EntityManagerFactory factory = Persistence.createEntityManagerFactory("userDatabase"); EntityManager em = factory.createEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> createQuery = cb.createQuery(String.class); Root<TestBean> from = createQuery.from(TestBean.class); Expression<String> param = cb.literal("DD.MM.YYYY"); createQuery.select(cb.function("TO_CHAR", String.class, from.get(TestBean_.date1), param)); List<String> resultList = em.createQuery(createQuery).getResultList();
    via by Max Hartmann,
  • HQL left join: Path expected for join
    via by Unknown author,
    • org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [...] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    1 more bugmates