[英]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. 我正在使用Hibernate,并且要进行批量更新,更改ID列表中所有对象的状态。 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
提前致谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.