I have tried to apply this solution to my own code:

This is the namedQuery I have placed on the entity:
        @NamedQuery(name="listDocumentTypesByCategories",     
                            query="SELECT dt FROM DocumentType dt, 
DocumentTypeCategoryLink dtcl
" +
                              "WHERE dt.documentTypeID = 
dtcl.documentType.documentTypeID " +
                              "AND dtcl.documentCategory.documentCategoryID IN 
(:catIDs) " +
                              "AND dt.invalid = 'false' " +
                                  "ORDER BY dt.name ASC")


This is how I am executing setting up/executing query following the
instructions posted in this forum:
                        Query q = 
em.createNamedQuery("listDocumentTypesByCategories");
                        q.setParameter("catIDs", Arrays.asList(new 
int[]{1,2,3})); 
                        List<DocumentType> objList = 
(List<DocumentType>)q.getResultList();

This is the error I am receiving upon execution:
java.lang.IllegalArgumentException: You have attempted to set a value of
type class java.util.Arrays$ArrayList for parameter catIDs with expected
type of int from query string SELECT dt FROM DocumentType dt,
DocumentTypeCategoryLink dtcl WHERE dt.documentTypeID =
dtcl.documentType.documentTypeID AND
dtcl.documentCategory.documentCategoryID IN (:catIDs) AND dt.invalid =
'false' ORDER BY dt.name ASC            


The query works fine if I just pass in a single int value, instead of trying
an array of int values?

Any help on this would be greatly appreciated.



On Tue, Aug 12, 2008 at 1:53 AM, Pinaki Poddar <[EMAIL PROTECTED]> wrote:
>
> Hi,
>> q.setParameter("roleIds", sb.toString());
>
>  Set the IN parameter not as a String but a List<T> where T is the type of
> Role.id.
>
>  For example, if Role.id is int, then
>   q.setParameter("roleIds", Arrays.asList(new int[]{1,2}));
>
>
> --
> View this message in context:
> http://n2.nabble.com/-JPQL--Problem-statement-SELECT-...-IN-%28%29-%2C-with-parameters-tp686295p686459.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>



-- 
View this message in context: 
http://n2.nabble.com/-JPQL--Problem-statement-SELECT-...-IN-%28%29-%2C-with-parameters-tp686295p839238.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to