I have a sql query like this
select column from table where path = left(\'INPUTSTRING\', length(path));
and trying to accomplish it in hql
I'm not sure if HQL does this for you , but you can use IQuery/session.CreateSQLQuery() to use a raw SQL query to populate a mapped entity. I've never used it for substrings, but have used it for aggregate functions. Check chapter 13 of the NHibernate docs and see if that does it for you. You can check the query substitution available in Nhibernate - here
Yes, left()
is not supported by the MySQLDialect
. See the list of HQL supported functions on API docs.
Now you have left with 2 options.
session.createSQLQuery()
method.Dialect
class by extending the MySQLDialect
and register the function there. This is told at hibernate forum here explained well in a blog post here.