For example, I have this query
select cat from Cat cat where cat.id in :ids
and I want to set ids to list (1,2,3,4,5,6,17,19).
This code doesn't work
session.createQuery("select cat from Cat cat where cat.id in :ids") .setParameter("ids", new Long[]{1,2,3,4,5})
As the result I would like to have SQL query like id in (1,2,3,4)
uniqueResult. Convenience method to return a single instance that matches the query, or null if the query returns no results.
It is an object oriented representation of Hibernate Query. The object of Query can be obtained by calling the createQuery() method Session interface.
Use setParameterList()
. You'll also have to put parenthesis around the list param.
session.createQuery("select cat from Cat cat where cat.id in (:ids)").setParameterList("ids", new Long[]{1,2,3,4,5})
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