Using java If I store windows paths in a h2 database, and then try and retrieve the objects using Hibernate by matching on the filename i.e
public static List<Object[]> findSongsRecNoAndModifiedDateWithinFolder(Session session, String folder)
{
Query q = session.createQuery("select recNo, filename, lastModified from Song t1 where t1.filename like :filename");
q.setParameter("filename", folder+'%', StandardBasicTypes.STRING);
List<Object[]> results = (List<Object[]>)q.list();
return results;
}
I get no matches.
If I convert all the '\' with '/' when I add to the database and try and retrieve it all works, but this is a bit of a pain I was trying to ignore the differences between UNIX and Windows files paths.
So the problem is something to do with Windows file separator '\' also being Java (and Database) escape character. but what I don't really understand is the problem with Java, the database or hibernate and if I can work round it.
See http://groups.google.com/group/h2-database/browse_thread/thread/390eed5e21584faa?pli=1 for an answer to your question:
\
is the default escape character in H2, and you need to escape it (with another\
) if you use it in a like clause.Or you can set the default escape character to an empty string to avoid this escaping problem. See http://www.h2database.com/javadoc/org/h2/constant/DbSettings.html and search for "defaultEscape".