How to use the left left function in hql
I have sql query like this
select column from table where path = left('INPUTSTRING', length(path));
and try to execute it in hql like this,
return session.createQuery("from Table where Path = left(:input, length(Path))").
query.setParameter("input", inputPath).
.list();
and getting this error
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: left near line 1
how to do it? What is the corresponding string function in hql? Is there a solution for this using the apis criteria query?
+3
source to share
2 answers
I'm not sure if HQL will do this for you, but you can use IQuery / session.CreateSQLQuery () to use a raw SQL query to populate the mapped object. I've never used it for substrings, but used it for aggregate functions. Check chapter 13 of the NHibernate docs and see if it works for you. You can check out Query Replacement in Nhibernate - here
0
source to share