I've seen the example in 10.4.1.4
Code:
List names = new ArrayList();
names.add("Izi");
names.add("Fritz");
Query q = sess.createQuery("from DomesticCat cat where cat.name in (:namesList)");
q.setParameterList("namesList", names);
List cats = q.list();
Which indicates that a named argument to a set can be an ArrayList of strings.
But does not inform as to what is fully possible.
[and maybe things have changed since that doc?
even an ArrayList full of string does not work for me, even when selecting on a string-valued field]
Three questions:
1) Can the binding argument be other than a List? can it be a java.util.Set, or a simple array?
Do generic types matter (i've tried both ways, no joy)
2) Is this notation expected to work for non-String valued fields? (like int or Integer)
3) When I bind a simple value for :arg in a query like: from Activity as act where act.id in (:arg)
it works (but only selects for that single value);
but binding :arg to any collection or array gets a ClassCastException;
As below, where i pass an ArrayList for an Integer-valued field. (does int vs Integer matter?)
Can you suggest why? or how to workaround?
Quote:
java.lang.ClassCastException: java.util.ArrayList
at org.hibernate.type.IntegerType.set(IntegerType.java:41)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:38)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:491)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
Answers and insight will be greatly appreciated.