I have a question as how to escape wild characters while using criteria.
http://opensource.atlassian.com/project ... se/HHH-284 discusses similar question with HQL's.
For example, if want to search all names which have a "ABC" string my criteria query would be
Code:
Criteria criteria = session.createCriteria( MyPojo.class );
criteria.add( Restrictions.like( "name", "%ABC%" ) );
List results = criteria.list();
and the above code is working perfectly.
But if I want to search with names which have a "%" character in it
Code:
Criteria criteria = session.createCriteria( MyPojo.class );
criteria.add( Restrictions.like( "name", "%%%" ) );
List results = criteria.list();
the above code will not work as expected. I was escaping the % character in %%% with %\\%% but still I am getting every name. Is there any other way to escape these wild character search?
With following names availabale,
names (
user%one,
ABC%one,
ABC,
user,
XYZ%,
%XYZ )
the results should be
results (
user%one,
ABC%one,
XYZ%,
%XYZ )
Has anyone had to work with such a scenario, and if could you guide me in getting some information atleast that would be helpful.