In SQL query name.length()
would not work, however you can use following
Query query = HibernateUtil.getSessionFactory().getCurrentSession().
createQuery("SELECT * from User where substring(name, 1, :length) like :name");
query.setParameter("length",name.length());
........
........