Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.5
Name and version of the database you are using: MS SQL Server (2000?)
Using the code below, I have been unable to find the Alias ":@;#[;]", though all others (without the special characters are found without a problem). It appears that hibernate does not escape the parameters provided to Restrictions.iLike(x,y) because I have tried not escaping any characters too, and that doesnt work.
I have read all the other posts on the area, but after trying everything I could think of based on what I could glean from those information sources, I am still without a solution.
Am I missing something fundamental in the API? If so, please point me towards it.
Thankyou for your help.
This is a method which I call to escape the SQL 'special' characters
Code:
CoreEJBLib.escapeSQLSpecials(strReturn) {
// now replace all "'" with "''"
strReturn = strInput.replaceAll("'", "''");
// now replace all "*" with "%" (note it is double escaped cos its a RegExp)
strReturn = strReturn.replaceAll("\\*", "%");
// now replace all "?" with "_" (note it is double escaped cos its a RegExp)
strReturn = strReturn.replaceAll("\\?", "_");
strReturn = strReturn.replaceAll("\\[", "\\\\[");
strReturn = strReturn.replaceAll("\\]", "\\\\]");
return strReturn;
}
This is the actual query code that I useCode:
Criteria c = entityManager.getSession().createCriteria(Alias.class);
c.add(Restrictions.ilike("id.desc",
CoreEJBLib.escapeSQLSpecials(
codeToSrchFor),
MatchMode.START));
List<Alias> aliases = c.list();