persistence@glassfish.java.net

AW: Problem binding collections to queries

From: Christian Kerwer <Christian.Kerwer_at_t-online.de>
Date: Thu, 7 Feb 2008 10:36:28 +0100

Thanks! There seems already beeing an issue for this #2484.

Also I'm disappointed that this won't work ether:
... where id in ( select l_Id from IN(:planningObjectIdList) l_Id )

It seems JPA is far from cool.


Christian Kerwer


-----Ursprüngliche Nachricht-----
Von: Wouter van Reeven [mailto:wouter_at_van.reeven.nl]
Gesendet: Donnerstag, 7. Februar 2008 10:15
An: persistence_at_glassfish.dev.java.net
Betreff: Re: Problem binding collections to queries

Hi,

On Thu, Feb 07, 2008 at 09:57:31AM +0100, Christian Kerwer wrote:
> I’m trying to bind a collection of Ids into a Query like this:
>
> Select p from Project p where p.id IN (:IdList)
>
> with IdList as Array of Long and field p.id of type Long.
>
> It will be quitted with the following exception:
>
> java.lang.ClassCastException:
>
> You have attempted to set a value of type class [Ljava.lang.Long; for
parameter
> planningObjectIdList with expected type of class java.lang.Long from query
> string select planObjStrLnk from PlanningObjectStructureLink
planObjStrLnk
> where planObjStrLnk.planningClassStructure.id = :planningClassStructureId
and
> planObjStrLnk.planningObject.id in (:planningObjectIdList)

The EJB Persistence spec states that the parameter types on both sides of
the IN
operator must be of the same type. In other words, you cannot have a Long on
one
side and an Array on the other side. Either you'll have to write out every
id in
the Array, like this

p.id IN (12, 134, 66334567884)

or you'll have to rewrite your query.



HTH, Wouter van Reeven

-- 
People: "If she weighs the same as a Duck, she's made of wood!"
Sir Bedevere: "And therefore...?"