problem description: With Hibernate 3.0 and MySQL 5.0 queries with the like operator return no results if term searched for contains a backslash. All queries perform without throwing any errors.
With records having values ""java", "carl.java", "dir2\\carl.java", and
"d:\\dir1\\carl.java", the find equal query correctly returns the appropriate record.
However the findEndsWith query returns 0 records for when searching on any pattern containing a back slash such as "dir2\\carl.java"
Since the quality test works, I claim that my string values are ok.
from the class TestThing:
Code:
public static List findEq (String key)throws Exception {
String query = "from TestThing where path = :key";
logger.info ("find equal " + key);
return find (query, key);
}
public static List findLikeEnd (String key) throws Exception {
String query = "from TestThing where path like :key";
logger.info ("find like end " + key);
return find (query, "%" + key);
}
private static List find(String query, String key) throws Exception {
Session session = Setup.getSession();
Query q = session.createQuery(query).setString("key", key);
List results = q.list();
logger.info ("result size = " + results.size());
return results;
}
from the test fixture:
Code:
public void testing() throws Exception {
logger.info("starting testing");
for (String p : paths){
TestThing thing = new TestThing();
thing.setPath(p);
thing.save();
}
for (String p : paths){
logger.info("for path = " + p);
List eqList = TestThing.findEq(p);
showList(eqList, "equal", p);
}
for (String p : paths){
List endList = TestThing.findLikeEnd(p);
showList(endList, "ends with", p);
}
}
private void showList(List list, String label, String key){
System.out.println("----------------------------------");
System.out.println("results for " + label + " " + key);
System.out.println(" size = " + list.size());
for (Object o : list){
TestThing thing = (TestThing)o;
System.out.println (" " + thing.getPath());
}
}
Hibernate version: 3.0
Mapping documents:Code between sessionFactory.openSession() and session.close():Name and version of the database you are using:MySQL 5.0 beta
The generated SQL (show_sql=true):Hibernate: select testthing0_.id as id, testthing0_.path as path5_ from thing testthing0_ where testthing0_.path=?
and
Code:
Hibernate: select testthing0_.id as id, testthing0_.path as path5_ from thing testthing0_ where testthing0_.path like ?
Debug level Hibernate log excerpt: