Hibernate – How to make a named query with IN actually work

collections, hibernate, jboss, jpa-2.0
class X {Y y; // manyToOne}class Y {Long id;}

@NamedQuery(name = "someName", query = "from X where y.id in :ids")

I have public, table, entity and all other things on the Entities but I didn't wrote them here.

TypedQuery<X> query = getEntityManager().createNamedQuery("someName", X.class);query.setParameter("ids", someListOfLongs); // HERE I GET THE ERRORqueryFinal.getResultList();

Parameter value [[Ljava.lang.Object;@90d0bf] was not matching type [java.lang.Long]

I tried with or without (), I changed the version of Hibernate-Core to 3.6.4 (from JBoss 6.0.0.Final), otherwise if I wrote in :ids without () I'd got an error.

Please Help.

The IN always worked, the problem was that List<Long> wasn't actually List<Long> was List<Object[]>. Thanks

Best Solution

I also use JBoss AS 6 and this exact construct, but it just works.

This is an example of a query:

<named-query name="Item.getByItemIDs">    <query>        SELECT            i        FROM            Item i        WHERE            i.ID in (:itemsIDs)    </query></named-query>

And of a class using it:

@Overridepublic List<Item> getByItemIDs(List<Long> itemIDs) {    return entityManager.createNamedQuery("Item.getByItemIDs", Item.class)                        .setParameter("itemIDs", itemIDs)                        .getResultList();}

As your exception indicated [[Ljava.lang.Object;@90d0bf] (which is an Object[]), maybe you should try List<Long> as in my example?

(p.s. You can use the fluid API of JPA to make your code a little less verbose)