Hibernate SQLQuery with list condition
I am trying to pass a list of integers to SQLQuery. However, it gives an error message"Exception : could not locate named parameter [ids]; nested exception is org.hibernate.QueryParameterException: could not locate named parameter [ids]"
This is what my request looks like:
List<Integer> ids = new ArrayList<Integer>(5);
//Fill something in ids
return session.createSQLQuery("select igf.foo_id from group_feed igf where igf.id in (:ids)")
.setMaxResults(pageSize)
.setParameterList("ids", ids)
.setResultTransformer(Transformers.aliasToBean(GroupFeed.class))
.list();
What am I doing wrong? Am I not allowed to use setParameterList
with Hibernate SQLQuery
? I haven't been able to figure out a lot from the Hibernate documentation in jBoss.
source to share
List<Integer> ids = new ArrayList<Integer>(5);
Creates an empty list with a capacity of 5 slots:
ids {null, null, null, null, null}
for (Integer i : ids) {
System.out.println("" + i);
}
Didn't print anything. The list is empty.
Are you sure the list is populated with at least one item?
The method Hibernate
looks for the parameters that I think you need:
return session.createSQLQuery("select igf.foo_id from group_feed igf where igf.id in ( :ids )")
.setMaxResults(pageSize)
.setParameterList("ids", ids)
.setResultTransformer(Transformers.aliasToBean(GroupFeed.class))
.list();
I think I do Hibernate
nβt know about :ids
, as it is (:ids)
.
source to share