openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Prashant Bhat <>
Subject Positional Parameters with update query
Date Sun, 30 Oct 2011 12:32:30 GMT

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.


    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);

        int result = q.executeUpdate();
        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?


View raw message