Assuming that I want to write the following HQL query:
FROM Cat c WHERE c.id IN (1,2,3)
what is the proper way of writing this as a parametrized query, e.g.
FROM Cat c WHERE c.id IN (?)
Hibernate Query Language (HQL) is an easy to learn and powerful query language designed as an object-oriented extension to SQL that bridges the gap between the object-oriented systems and relational databases. The HQL syntax is very similar to the SQL syntax.
Hibernate Query Language (HQL) is an object-oriented query language, similar to SQL, but instead of operating on tables and columns, HQL works with persistent objects and their properties. HQL queries are translated by Hibernate into conventional SQL queries, which in turns perform action on database.
Hibernate provides three different ways to retrieve data from a database.
I am unsure how to do this with positional parameter, but if you can use named parameters instead of positional, then named parameter can be placed inside brackets and setParameterList method from Query interface can be used to bind the list of values to this parameter.
... Query query = session.createQuery("FROM Cat c WHERE c.id IN (:ids)"); query.setParameterList("ids", listOfIds); ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With