Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

Re: [JPQL] Problem statement SELECT ... IN () , with parameters

ajcnb

2008-09-04

Replies: Find Java Web Hosting

Author LoginPost Reply

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 <ppoddar@(protected):
>
> 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.
>
>



--
Sent from the OpenJPA Users mailing list archive at Nabble.com.

©2008 gg3721.com - Jax Systems, LLC, U.S.A.