OPENJPA-1458: fix named parameter problem

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@898936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2010-01-13 20:49:01 +00:00
parent c21fdc5512
commit 2331d20522
3 changed files with 18 additions and 4 deletions

View File

@ -1614,8 +1614,7 @@ public class JPQLExpressionBuilder
throw parseException(EX_USER, "bad-positional-parameter",
new Object[]{ id }, null);
} else {
// otherwise the index is just the current size of the parameters
index = parameterTypes.size()-1;
index = parameterTypes.indexOf(id);
}
Parameter param = isCollectionValued
? factory.newCollectionValuedParameter(paramKey, TYPE_OBJECT)

View File

@ -52,7 +52,7 @@ public class OrderedMap<K, V> implements Map<K, V>, Serializable {
public int indexOf(Object key) {
int i = 0;
for (K k : _del.keySet()) {
if (key == k)
if (key.equals(k))
return i;
i++;
}

View File

@ -18,6 +18,8 @@
*/
package org.apache.openjpa.persistence.jdbc.query;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
@ -248,7 +250,20 @@ public class TestQueryParameterBinding extends SingleEMFTestCase {
fail(q);
}
public void testRepeatedNamedParameters() {
String JPQL_POSITIONAL =
JPQL + "WHERE p.p1 in (select max(p.p1) from Binder p where p.p1=:p1 AND p.p2=:p2 AND p.p3=:p3) "
+ "AND p.p1=:p1 AND p.p2=:p2 AND p.p3=:p3";
Query q = em.createQuery(JPQL_POSITIONAL);
q.setParameter("p1", INT_VALUE);
q.setParameter("p2", STR_VALUE);
q.setParameter("p3", DBL_VALUE);
List list = q.getResultList();
assertEquals(1, list.size());
}
void assertSetParameterFails(Query q, String name, Object v) {
try {
q.setParameter(name, v);