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