persistence@glassfish.java.net

RE: [Fwd: [Issue 928] Positional parameters for NamedNativeQuery]

From: Mike Keith <michael.keith_at_oracle.com>
Date: Tue, 22 Aug 2006 16:43:30 -0400

Hi Michael and Marina,

You have both asked the same question (Michael's attached) so I am merging
my responses into one.

It was indeed the intention that the spec not require that native queries
be parsed or manipulated. While this was stated numerous times in our
discussions it was not actually explicitly stated in the spec (nor
should it need to be, really). The point was that the spec not make any
requirements that would necessitate an implementer having to do so.

The question, then, is about the comment in 3.6.6 that says:
"Only positional parameter binding may be portably used for native queries."

My intent was that it be JDBC parameter style with only question marks and
no parameter numbers. Although describing it as being positional meant
that to me, I realize that the wording is very ambiguous, especially given that
we talk about positional parameters in the other query sections as being with
integer parameter numbers. Rather unfortunate.

Given the confusion, though, TopLink has been changed to allow both.

-Mike

> -----Original Message-----
> From: Marina.Vatkina_at_Sun.COM
> [mailto:Marina.Vatkina_at_Sun.COM]On Behalf Of
> Marina Vatkina
> Sent: Tuesday, August 22, 2006 4:04 PM
> To: Linda DeMichiel; Mike Keith; persistence
> Subject: [Fwd: [Issue 928] Positional parameters for NamedNativeQuery]
>
>
> Linda, Mike,
>
> I thought that the spec doesn't require parsing of a native query,
> but I can't find such statement.
>
> Or does this statement refer to the Query API rather than the SQL,
> and mean something to the extent that setParameter(n, value)
> just passes
> it through to the prepared statement?
>
> thanks,
> -marina
>
> -------- Original Message --------
> From: mareks_at_dev.java.net
> Subject: [Issue 928] Positional parameters for NamedNativeQuery
> To: issues_at_glassfish.dev.java.net
>
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=928
>
>
>
>
>
>
> ------- Additional comments from mareks_at_dev.java.net Tue Aug
> 22 19:48:33 +0000
> 2006 -------
> 3.6.3 Named Parameters
> A named parameter is an identifier that is prefixed by the
> ":" symbol. Named
> parameters are case-sen-
> sitive.
> Named parameters follow the rules for identifiers defined in
> Section4.4.1. The
> use of named parameters
> applies to the JavaPersistence query language, and is not
> defined for native
> queries. Only positional
> parameter binding may be portably used for native queries.
>
> =========================================================
>
> page 69; ejb-3_0-fr-spec-persistence.pdf
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: issues-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: issues-help_at_glassfish.dev.java.net
>
>
>

attached mail follows:



Hi Linda, hi Mike,

there have been forum posts around input parameters for native queries.
Some of them use the Java Persistence Query syntax for positional
parameters: a question mark followed by a number, e.g. ?1. Is this
syntax supposed to be supported for native queries?

I assume I have to use the JDBC parameter syntax in native queries (a
question mark w/o number). Otherwise the persistence provider would need
to process the SQL query text before passing it to the JDBC layer.

The spec mentions input parameters for native queries in sections 3.6.3
and 3.6.6; e.g. it says: "Only positional parameter binding may be
portably used for native queries.". I understand this refers to method
Query.setParameter taking a position and not to the parameter syntax
used in the SQL query text, but others might read this different.

Regards Michael