HibernateQueryException:预期的位置参数计数,但查询w / o参数

时间:2016-10-12 11:21:42

标签: java mysql hibernate

在执行查询期间,我收到错误Expected positional parameter count: 1, actual parameters: []我的查询没有任何参数,但是查询包含作为值。

session.createSQLQuery(sql).list()

SQL

SELECT file.name as `NAME` FROM film WHERE film.name IN ('You say "How I can make it? We' ..."');

修改

如果按名称搜索包含'

,它也会重现
SELECT file.name as `NAME` FROM film WHERE film.name IN ('?'')

我该如何解决?

感谢。

1 个答案:

答案 0 :(得分:1)

应该工作

String[] values= {"You say \"How I can make it? We' ...\""};
String sql = "SELECT file.name as `NAME` FROM film WHERE film.name IN (:values)";
SQLQuery query = session.createSQLQuery(sql);
query.setParameterList("values", values);

然后

query.list();