jpql named parameter list as input does not work

View: New views
4 Messages — Rating Filter:   Alert me  

jpql named parameter list as input does not work

by Thomas Rost :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We try to pass named parameter as a list in a jpql query. But we get the following error:

{SELECT returnValue FROM Need returnValue WHERE  returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) }

{SELECT returnValue FROM Need returnValue WHERE returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) }

 INFO Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter BUID with expected type of class java.lang.String from query string

SELECT returnValue FROM Need returnValue WHERE  returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) .

 INFO   at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:975)
 INFO   at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:862)
 ...

Info: it works with hibernate and we have a workaround by transforming list content into a comma separated string.

Question: Bug or wrong usage of named parameter?

Kind regards,
Tom

Re: jpql named parameter list as input does not work

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This was not supported in JPA 1.0/EclipseLink 1.1, but is supported in JPA 2.0/EclipseLink 2.0/1.2.

What version are you using?


Thomas Rost wrote:
We try to pass named parameter as a list in a jpql query. But we get the following error:

{SELECT returnValue FROM Need returnValue WHERE  returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) }

{SELECT returnValue FROM Need returnValue WHERE returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) }

 INFO Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter BUID with expected type of class java.lang.String from query string

SELECT returnValue FROM Need returnValue WHERE  returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) .

 INFO   at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:975)
 INFO   at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:862)
 ...

Info: it works with hibernate and we have a workaround by transforming list content into a comma separated string.

Question: Bug or wrong usage of named parameter?

Kind regards,
Tom

Re: jpql named parameter list as input does not work

by Thomas Rost () :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We use JPA 1.0/EclipseLink 1.2 RC3 and it does not work.
We found out it works without the brackets in the query: X IN :BUID instaed of X IN (:BUID).

Question: It's a feature or a bug? In Hibernate brackets are mandatory.


This was not supported in JPA 1.0/EclipseLink 1.1, but is supported in JPA 2.0/EclipseLink 2.0/1.2.

What version are you using?


Thomas Rost wrote:
We try to pass named parameter as a list in a jpql query. But we get the following error:

{SELECT returnValue FROM Need returnValue WHERE  returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) }

{SELECT returnValue FROM Need returnValue WHERE returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) }

 INFO Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter BUID with expected type of class java.lang.String from query string

SELECT returnValue FROM Need returnValue WHERE  returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) .

 INFO   at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:975)
 INFO   at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:862)
 ...

Info: it works with hibernate and we have a workaround by transforming list content into a comma separated string.

Question: Bug or wrong usage of named parameter?

Kind regards,
Tom


Re: jpql named parameter list as input does not work

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It definitely should not have brackets, brackets would mean you are binding a value inside the list, not the entire list.  This is the JPA 2.0 grammar.


We use JPA 1.0/EclipseLink 1.2 RC3 and it does not work.
We found out it works without the brackets in the query: X IN :BUID instaed of X IN (:BUID).

Question: It's a feature or a bug? In Hibernate brackets are mandatory.

James Sutherland wrote:
This was not supported in JPA 1.0/EclipseLink 1.1, but is supported in JPA 2.0/EclipseLink 2.0/1.2.

What version are you using?


Thomas Rost wrote:
We try to pass named parameter as a list in a jpql query. But we get the following error:

{SELECT returnValue FROM Need returnValue WHERE  returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) }

{SELECT returnValue FROM Need returnValue WHERE returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) }

 INFO Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter BUID with expected type of class java.lang.String from query string

SELECT returnValue FROM Need returnValue WHERE  returnValue.type  = '001' and  (  returnValue.type  = :type or  returnValue.BUID  IN (:BUID)  ) .

 INFO   at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:975)
 INFO   at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:862)
 ...

Info: it works with hibernate and we have a workaround by transforming list content into a comma separated string.

Question: Bug or wrong usage of named parameter?

Kind regards,
Tom