Domanda

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");
È stato utile?

Soluzione

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());
........
........
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top