openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Prashant Bhat <prashant...@gmail.com>
Subject Re: Positional Parameters with update query
Date Tue, 01 Nov 2011 14:53:53 GMT
Hi Mike,

The query works with this compatibility option. The issue
OPENJPA-1999<https://issues.apache.org/jira/browse/OPENJPA-1999> is
for non-sequential positional parameters, but  in this query, parameters
are specified in correct sequence. So IMO this should be enabled by default.

I've set this option in our application now and tested all other queries to
be working also. Thanks.

Regards,
Prashant

On Tue, Nov 1, 2011 at 9:07 AM, Michael Dick <michael.d.dick@gmail.com>wrote:

> Hi Prashant,
>
> This sounds like
> OPENJPA-1999<https://issues.apache.org/jira/browse/OPENJPA-1999>.
> Can you try adding the compatibility option to enable non sequential
> parameters?
>
> Here's the relevant property for persistence.xml :
> <property name="openjpa.Compatibility"
> value="ConvertPositionalParametersToNamed=true"/>
>
> -mike
>
> On Sun, Oct 30, 2011 at 7:32 AM, Prashant Bhat <prashant.mr@gmail.com
> >wrote:
>
> > Hi,
> >
> > When positional parameters are used with IN (select ...) query as in the
> > below test case, OpenJpa throws an error that "JPQL positional parameters
> > must start at 1". The same query with named parameters works.
> >
> >
> >
> openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestQueryParameterBinding.java
> >
> >     public void testPositionalParametersWithUpdateQuery() {
> >         String JPQL_POSITIONAL = "UPDATE Binder p SET p.p3=?1 WHERE p.p1
> > IN "
> >   + " (SELECT x.p1 FROM Binder x WHERE x.p1=?2) AND p.p2=?3";
> >         Query q = em.createQuery(JPQL_POSITIONAL);
> >         q.setParameter(1,  DBL_VALUE);
> >         q.setParameter(2,  INT_VALUE);
> >         q.setParameter(3,  STR_VALUE);
> >
> >  em.getTransaction().begin();
> >         int result = q.executeUpdate();
> > em.getTransaction().commit();
> >         assertEquals(1, result);
> >     }
> >
> > <openjpa-2.2.0-SNAPSHOT-r422266:1195104M nonfatal user error>
> > org.apache.openjpa.persistence.ArgumentException: Query "UPDATE Binder p
> > SET p.p3 = ?1 WHERE p.p1 in (SELECT x.p1 FROM Binder x WHERE x.p1=?2) AND
> > p.p2=?3" did not contain positional parameter 1. JPQL positional
> parameters
> > must start at 1. Detected parameters "[2]".
> >
> > In our application I was able to workaround this error, by adding ?1 = ?1
> > to the where clause! So it's is not a critical issue, but would be useful
> > improvement. Should I create a Jira Issue for this?
> >
> > Regards,
> > Prashant
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message