在where子句中使用like命名查询 [英] Named Query with like in where clause
本文介绍了在where子句中使用like命名查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在命名查询的where子句中使用like?我正在尝试执行以下操作但遇到异常
Is it possible to have a like in a where clause in a named query? I am trying to do the following but am getting exceptions
@NamedQuery(name = "Place.getPlaceForCityAndCountryName",
query = "SELECT p FROM Place p WHERE " +
"lower(p.city) like :city and " +
"lower(p.countryName) like :countryName");
我尝试添加%,就像在普通SQL中一样,但得到异常编译。
I tried adding % as you would do in normal SQL but get exceptions compiling.
任何指针都非常感谢!
谢谢
推荐答案
你不能在 NamedQuery
中拥有%,但你可以在赋值参数的值中得到它。
You can't have the % in the NamedQuery
, but you can have it in the value you assign the parameter.
如:
String city = "needle";
query.setParamter("city", "%" + city + "%");
这篇关于在where子句中使用like命名查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文