Pergunta

How do I perform substring with a parameter's length?

i.e.

Query query = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("SELECT * from User where substring(name, 1, :name.length()) like :name");
Foi útil?

Solução

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());
........
........
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top