Hibernate 如何在“中转义通配符”;例如;条款
如何转义like子句中的通配符 例如: 从foo中选择foo作为foo,其中foo.bar类似于“%”过滤器“%” query.setParameter(“过滤器”、“%”); query.list(); //我希望在bar中得到包含“%”的foo,而不是所有foo!Hibernate 如何在“中转义通配符”;例如;条款,hibernate,hql,wildcard,Hibernate,Hql,Wildcard,如何转义like子句中的通配符 例如: 从foo中选择foo作为foo,其中foo.bar类似于“%”过滤器“%” query.setParameter(“过滤器”、“%”); query.list(); //我希望在bar中得到包含“%”的foo,而不是所有foo! 有什么想法吗?在Hibernate 3中,可以使用escape参数指定escape字符: select foo from Foo as foo where foo.bar like '!%' escape '!' 我认为这应该行
有什么想法吗?在Hibernate 3中,可以使用escape参数指定escape字符:
select foo from Foo as foo where foo.bar like '!%' escape '!'
我认为这应该行得通,尽管我从未在实践中尝试过。@DeanPovey对我的不起作用:
原因:org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:在第1行第175列附近转义[选择e.id,e.title,e.type.icon,e.typeObject,e.idDomain from package.SomeClass e where(大写(e.title)LIKE?)和e.idDomain=?escape'!']
query.setParameter("filter", "%");
query.list();
// I'd expect to get the foo's containing the '%' in bar, not all of them!
select foo from Foo as foo where foo.bar like '!%' escape '!'