How to avoid wildcards in a "like" article in HQL?

How can I avoid wildcards in a similar section?

eg:.

 select foo from Foo as foo where foo.bar like '%' ||  : filter || '%'
 query.setParameter ("filter", "%");
 query.list (); 
 // I'd expect to get the foo containing the '%' in bar, not all of them!

Any ideas?

+7
wildcard hibernate hql like
source share
1 answer

In Hibernate 3, you can use the escape parameter to specify an escape char:

select foo from Foo as foo where foo.bar like '!%' escape '!' 

I think this should work, although I have never tried it in practice.

+11
source share

All Articles