Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 如何在“中转义通配符”;例如;条款_Hibernate_Hql_Wildcard - Fatal编程技术网

Hibernate 如何在“中转义通配符”;例如;条款

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 '!' 我认为这应该行

如何转义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 '!'

我认为这应该行得通,尽管我从未在实践中尝试过。

@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 '!'