Hibernate throws the pending OPEN found '+'

there is my hql below:

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

and below is the exception information:

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)

I want to update the user set = count + xx, where id = xx. but received a syntax error. What for? is this not support in hql ?? How to solve this problem?

+4
source share
2 answers

the problem is the name of the field; it is a reserved word and should be indicated.
Expected OPENmeans the HQL parser expects an count(<expression>)SQL expression , not count = .... The only solution is to alias Userand force the dot field name as:

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

+5
source
Query query = session.createQuery("update User set count = count + :count" +" where id = :Id");
query.setParameter("Id", id);
query.setParameter("count", count);
+1
source

Source: https://habr.com/ru/post/1529758/


All Articles