org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [...]

Hibernate JIRA | Mathias Hasselmann | 1 decade ago
  1. 0

    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

    Hibernate JIRA | 1 decade ago | Mathias Hasselmann
    org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [...]
  2. 0

    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

    Hibernate JIRA | 1 decade ago | Mathias Hasselmann
    org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [...]
  3. 0

    How to use inner join query in hql?

    Stack Overflow | 2 years ago | Akshant poonia
    org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 74 [select user_name, message from com.csc.project.user e inner join tweet p on p.user_id=e.id where e.user_name=:name]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Hibernate Community • View topic - Using List in HQL WHERE clause

    hibernate.org | 8 months ago
    org.springframework.orm.hibernate3.HibernateQueryException: expecting IDENT, found ':' near line 1, column 175 [select l from Location as l where l.latitude = :lat and l.longitude = :long and l.category.code in elements(:codes)]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: expecting IDENT, found ':' near line 1, column 175 [select l from Location as l where l.latitude = :lat and l.longitude = :long and l.category.code in elements(:codes)]
  6. 0

    Erro de persistência. Hibernate + duas chaves primárias !!

    com.br | 1 year ago
    org.hibernate.hql.ast.QuerySyntaxException: unexpected token: values near line 1, column 120 [insert into NBS.PRISMA_BOX_RESERVA (prisma, data_comeca, data_termina, motivo, placa, crm_cod_empresa, crm_cod_evento) values ('XXXXX', TO_DATE('24/01/2012 08:00','DD/MM/YYYY HH24:MI'), TO_DATE('24/01/2012 08:00','DD/MM/YYYY HH24:MI'), 'On Line. Sr(a) XXXXXXXX', '123456', null, null)]

    6 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.hql.ast.QuerySyntaxException

      unexpected AST node: query [...]

      at org.hibernate.hql.ast.ErrorCounter.throwQueryException()
    2. Hibernate HQL/JP-QL Parser
      QueryTranslatorImpl.compile
      1. org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
      2. org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225)
      3. org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
      4. org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
      4 frames
    3. Hibernate
      SessionImpl.createQuery
      1. org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
      2. org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
      3. org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
      4. org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
      5. org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
      6. org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
      6 frames