是否可以在命名查询的 where 子句中使用 like?我正在尝试执行以下操作,但遇到异常
@NamedQuery(name = "Place.getPlaceForCityAndCountryName",
query = "SELECT p FROM Place p WHERE " +
"lower(p.city) like :city and " +
"lower(p.countryName) like :countryName");
我尝试像在普通 SQL 中那样添加 %,但编译时会出现异常。
任何指针都非常感谢!
谢谢
最佳答案
您不能在 NamedQuery
中包含 %,但您可以在分配参数的值中包含它。
如:
String city = "needle";
query.setParamter("city", "%" + city + "%");
关于java - 在 where 子句中带有 like 的命名查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10912320/