Hibernate抛出一个期待的OPEN,找到'+' [英] Hibernate throws a expecting OPEN, found '+'

查看:178
本文介绍了Hibernate抛出一个期待的OPEN,找到'+'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的hql:

there is my hql below:

update User set count = count + ?2 where id = ?1

,并有以下例外情况:

and there is exception details below:

org.hibernate.hql.internal.ast.QuerySyntaxException: expecting OPEN, found '+' near line 1, column 71 [update com.yitaosoft.edm.common.persist.entity.User set count = count + ? where id = ?]
    at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
    at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
    at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:278)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)

我想更新用户设置count = count + xx其中id = xx。但有一个语法错误。为什么?在hql中不支持?如何解决这个问题??解决方案

I want to update user set count = count + xx where id = xx. but got a syntax error. why ? is it not support in hql ?? how to solve this issue ??

解决方案

问题是fieldname count;这是一个保留字,应该引用。
Expected OPEN 表示HQL解析器期待 count(< expression> ) SQL表达式而不是 count = ...
唯一的解决方案是别名 User 并强制虚线字段名为:

the problem is the fieldname count; it is a reserved word and should be quoted.
Expected OPEN means HQL parser is expecting count(<expression>) SQL expression and not count = .... The only solution is to alias User and force dotted fieldname as:

update User u set u.count =(u.count +?)where id =?

这篇关于Hibernate抛出一个期待的OPEN,找到'+'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆