HQL意外的AST节点:意外的AST节点:

时间:2015-06-23 16:21:33

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

我遇到了这个例外:

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
)

我的查询是:

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)]

此查询在MySQL中运行,但它在我的应用程序中无法运行

例外是:

{{1}}

1 个答案:

答案 0 :(得分:2)

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

因此,您应该使用session.createSQLQuery()代替session.createQuery()来代替HQL实体查询。