openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@gmail.com>
Subject Re: getPositionalParameters/getNamedParameters/hasPositionalParameters behavior
Date Mon, 04 Jun 2007 20:25:58 GMT
I believe that it's only meaningful to invoke that method after having
set parameters. So, that method is not there for introspection of the
query definition, but rather for obtaining parameters set via
setParameter(...).

If you want to get details about the declared parameters in the query
definition, you'll need to dig into the
org.apache.openjpa.kernel.Query that backs the query instance:

org.apache.openjpa.kernel.Query kernelQuery = ((QueryImpl) q).getDelegate();
Map params = kernelQuery.getParameterTypes();

Clearly, that's not part of the extension API, but it'll do the trick.

-Patrick

On 6/4/07, Reddy SMK <smkreddy2001@gmail.com> wrote:
> Hi Guys
>
> i tried these method for some reason i am not getting the expected
> results.... has any one tried these methods? i have the following named
> query...
>
> SELECT x FROM Magazine x, IN(x.articles) y WHERE y.authorName = :personName,
> when i use the getNamedParameters on the it returns an empty map...
>
>
>             Query query = em.createNamedQuery(jpql);
>             OpenJPAQuery jpaQuery = OpenJPAPersistence.cast(query);
>             if (jpaQuery.hasPositionalParameters())
>                 throw new QueryException(
>                         "The query does not has named parameters please
> check your arguments");
>
>             Map namedParamMap = (Map) jpaQuery.getNamedParameters();
>
>
> in this case, based on the documentation, should expect a map with one
> entry.. but for some reason i am getting null map..
>
> same for the positional args
> SELECT x FROM Magazine x, IN(x.articles) y WHERE y.authorName = ?1, when i
> use the getPositionalParameters on the it returns an empty map...
>
>            Query query = em.createNamedQuery(jpql);
>             OpenJPAQuery jpaQuery = OpenJPAPersistence.cast(query);
>             jpaQuery.compile();
>             if (!jpaQuery.hasPositionalParameters())
>                 throw new QueryException(
>                         "The query does not has positional parameters please
> check your arguments");
>             Object[] positionParamArray = (Object[]) jpaQuery
>                     .getPositionalParameters();
>
>
> I am not sure if my understanding is wrong or the methods are not behaving
> appropriately...
>


-- 
Patrick Linskey
202 669 5907

Mime
View raw message