简体   繁体   中英

Hibernate Query Language (HQL) Update list

I'm using Hibernate and I want to make a bulk update, changing the status of all objects within a list of ids. So I tried:

String update = "UPDATE Foo as foo SET foo.status = :status WHERE foo.id in (:idList)"

Which caused an exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;

I also tried:

String update = "UPDATE Foo as foo SET foo.status = :status WHERE foo.id in (SELECT id FROM Foo WHERE id in (:idList))"

That caused the same exception.

I'm inserting the parameters like this:

StatelessSession ss = sessionFactory.openStatelessSession();
Query query = ss.createQuery(update);
query.setParameter("status", status);
query.setParameterList("idList", ids);
query.executeUpdate();

Any ideas how to make this work? Thanks in advance

Status is a MySQL reserved word. Rename your column to something else

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM