How do I get records that first 4 characters' match my string using HQL?
This is my HQL statement:
Query query = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("from User where substring(user, 4) like :user");
query.setParameter("user", "John");
Which returns nothing. However, if I reuse the SQL statement in MySQL and change the word "substring" to LEFT
then it returns a lot of records.
I've also tried replacing "substring" with "left" in my HQL but it gives me this error when I do:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: LEFT