【问题标题】:HQL unexpected AST node:unexpected AST node:HQL 意外的 AST 节点:意外的 AST 节点:
【发布时间】:2015-06-23 16:21:32
【问题描述】:

我遇到了这个异常:

unexpected AST node: query

我的查询是:

SELECT  u.user_id, u.username,u.email,u.phone,u.status,r.rolename 
FROM user_registration u, roles r 
WHERE u.user_id=r.role_id IN (
    select ur.role_id  from roles ur where ur.role_id=u.user_id
)

此查询在 MySQL 中运行,但在我的应用程序中不起作用

例外是:

SEVERE: Servlet.service() for servlet [spring] in context with path [/jaga] threw exception [Request processing failed; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: in near line 1, column 196 [SELECT  u.user_id, u.username,u.email,u.phone,u.status,r.rolename FROM com.jagahunt.admin.usermanagement.entity.User u, com.jagahunt.admin.usermanagement.entity.Role r WHERE u.user_id=r.role_id  IN (select ur.role_id  from com.jagahunt.admin.usermanagement.entity.Role ur where ur.role_id=u.user_id)]] with root cause
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: in near line 1, column 196 [SELECT  u.user_id, u.username,u.email,u.phone,u.status,r.rolename FROM com.jagahunt.admin.usermanagement.entity.User u, com.jagahunt.admin.usermanagement.entity.Role r WHERE u.user_id=r.role_id  IN (select ur.role_id  from com.jagahunt.admin.usermanagement.entity.Role ur where ur.role_id=u.user_id)]

【问题讨论】:

  • WHERE u.user_id=r.role_id IN(select ...。那是无效的。用户 ID 等于某个值,或者它在子选择中。但是你不能像这样连接这两个限制。

标签: java sql hibernate orm abstract-syntax-tree


【解决方案1】:

这是您尝试执行的本机查询。

因此,您应该为此使用 session.createSQLQuery(),而不是采用 HQL 实体查询的 session.createQuery()

【讨论】:

    猜你喜欢
    • 2013-09-28
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 2022-09-29
    相关资源
    最近更新 更多