You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Kevin Sutter <kw...@gmail.com> on 2007/10/17 18:29:42 UTC

error message for native sql parameters

Hi,
One of our customers stumbled over this error message when parsing a
@NamedNativeQuery:

bad-param-name: The parameter name or position "{0}" passed to \
    execute() is not valid.  All map keys must be a declared parameter \
    name or a number matching the parameter position.

The @NamedNativeQuery was as follows:

@NamedNativeQuery(name="getStationKeyForUpdate",
        query="SELECT * from KEYGEN where KEYNAME = :keyname FOR UPDATE")

Native Queries only allow positional parameters.  This customer thought that
the error message should be clearer since it mentions that named parameters
may also be allowed.

I looked at the code in question and we use the same processing for named
and positional parameter for both jpql and native queries.  So, it would be
overkill (in my mind) to separate out the processing just to clarify the
syntax requirements of the various queries.

So, would there be any problem with just adding the following to the error
message:

bad-param-name: The parameter name or position "{0}" passed to \
    execute() is not valid.  All map keys must be a declared parameter \
    name or a number matching the parameter position.  Native queries \
    only allow positional parameters.

It clarifies the problem without introducing a lot of extra processing.

Kevin

Re: error message for native sql parameters

Posted by Patrick Linskey <pl...@gmail.com>.
Sounds like a good solution to me.

-Patrick

On 10/17/07, Kevin Sutter <kw...@gmail.com> wrote:
> Hi,
> One of our customers stumbled over this error message when parsing a
> @NamedNativeQuery:
>
> bad-param-name: The parameter name or position "{0}" passed to \
>     execute() is not valid.  All map keys must be a declared parameter \
>     name or a number matching the parameter position.
>
> The @NamedNativeQuery was as follows:
>
> @NamedNativeQuery(name="getStationKeyForUpdate",
>         query="SELECT * from KEYGEN where KEYNAME = :keyname FOR UPDATE")
>
> Native Queries only allow positional parameters.  This customer thought that
> the error message should be clearer since it mentions that named parameters
> may also be allowed.
>
> I looked at the code in question and we use the same processing for named
> and positional parameter for both jpql and native queries.  So, it would be
> overkill (in my mind) to separate out the processing just to clarify the
> syntax requirements of the various queries.
>
> So, would there be any problem with just adding the following to the error
> message:
>
> bad-param-name: The parameter name or position "{0}" passed to \
>     execute() is not valid.  All map keys must be a declared parameter \
>     name or a number matching the parameter position.  Native queries \
>     only allow positional parameters.
>
> It clarifies the problem without introducing a lot of extra processing.
>
> Kevin
>


-- 
Patrick Linskey
202 669 5907