如何在like子句中转义通配符?
E.g:
select foo from Foo as foo where foo.bar like '%' || :filter ||'%'
query.setParameter("filter", "%"); query.list(); // I'd expect to get the foo's containing the '%' in bar, not all of them!
有什么想法吗?
答案 0 :(得分:12)
在Hibernate 3中,您可以使用escape参数指定转义字符:
select foo from Foo as foo where foo.bar like '!%' escape '!'
我认为这应该有用,虽然我从未在实践中尝试过。