diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
index a206f3b2f..de5df78bb 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
@@ -1160,7 +1160,7 @@ public class JPQLExpressionBuilder
if (fmd == null)
return;
- Class type = path.isXPath() ? path.getType() : fmd.getType();
+ Class type = path.isXPath() ? path.getType() : fmd.getDeclaredType();
if (type == null)
return;
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
index cb3494309..c6db1d288 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
@@ -19,18 +19,26 @@
package org.apache.openjpa.persistence.meta;
+import java.util.List;
+import java.util.UUID;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
import org.apache.openjpa.persistence.meta.common.apps.ExternalValues;
import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+import org.apache.openjpa.persistence.ArgumentException;
import org.apache.openjpa.persistence.OpenJPAEntityManager;
/**
*
Tests the {@link ExternalValuesFieldMapping}.
*
* @author Abe White
+ * @author Pinaki Poddar (added binding query parameter tests)
*/
public class TestExternalValues
extends AbstractTestCase {
-
+
public TestExternalValues(String test) {
super(test, "metacactusapp");
}
@@ -55,7 +63,6 @@ public class TestExternalValues
pc.setDoubleToByte(4.5);
pc.setCharToInt('f');
pc.setStringToLong("foo");
-
pm.persist(pc);
Object oid = pm.getObjectId(pc);
endTx(pm);
@@ -112,4 +119,77 @@ public class TestExternalValues
pc = (ExternalValues) pm.find(ExternalValues.class, oid);
endEm(pm);
}
+
+ public void testPositionalBindingQueryParameterEqualsDeclaredType() {
+ UUID uuid = new UUID(1,4);
+ createInstance(uuid);
+
+ EntityManager em = currentEntityManager();
+ String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=?1";
+ List result = em.createQuery(jpql)
+ .setParameter(1, uuid)
+ .getResultList();
+ assertFalse(result.isEmpty());
+ for (ExternalValues x:result) {
+ assertEquals(uuid, x.getUuid());
+ }
+ }
+
+ public void testNamedBindingQueryParameterEqualsDeclaredType() {
+ UUID uuid = new UUID(2,4);
+ createInstance(uuid);
+
+ EntityManager em = currentEntityManager();
+ String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=:uuid";
+ List result = em.createQuery(jpql)
+ .setParameter("uuid", uuid)
+ .getResultList();
+ assertFalse(result.isEmpty());
+ for (ExternalValues pc:result) {
+ assertEquals(uuid, pc.getUuid());
+ }
+ }
+
+ public void testPositionalBindingQueryParameterNotEqualsExternalizedType() {
+ UUID uuid = new UUID(1,4);
+ createInstance(uuid);
+
+ EntityManager em = currentEntityManager();
+ String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=?1";
+ Query query = em.createQuery(jpql)
+ .setParameter(1, uuid.toString());
+
+ try {
+ query.getResultList();
+ fail("Expected ArgumentException");
+ } catch (ArgumentException ex) {
+ // expected
+ }
+ }
+
+ public void testNamedBindingQueryParameterNotEqualsExternalizedType() {
+ UUID uuid = new UUID(2,4);
+ createInstance(uuid);
+
+ EntityManager em = currentEntityManager();
+ String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=:uuid";
+ Query query = em.createQuery(jpql)
+ .setParameter("uuid", uuid.toString());
+ try {
+ query.getResultList();
+ fail("Expected ArgumentException");
+ } catch (ArgumentException ex) {
+ // expected
+ }
+ }
+
+ private void createInstance(UUID uuid) {
+ EntityManager em = currentEntityManager();
+ em.getTransaction().begin();
+ ExternalValues pc = new ExternalValues();
+ pc.setUuid(uuid);
+ em.persist(pc);
+ em.getTransaction().commit();
+ em.clear();
+ }
}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
index 7fc91dd12..2c2920d83 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
@@ -19,8 +19,14 @@
package org.apache.openjpa.persistence.meta.common.apps;
+import java.util.UUID;
+
import javax.persistence.Entity;
+import org.apache.openjpa.persistence.Externalizer;
+import org.apache.openjpa.persistence.Factory;
+import org.apache.openjpa.persistence.Persistent;
+
@Entity
public class ExternalValues {
@@ -33,6 +39,10 @@ public class ExternalValues {
private double doubleToByte;
private char charToInt;
private String stringToLong;
+ @Persistent
+ @Externalizer("toString")
+ @Factory("UUID.fromString")
+ private UUID uuid;
public boolean getBooleanToShort() {
return booleanToShort;
@@ -105,4 +115,12 @@ public class ExternalValues {
public void setStringToLong(String s) {
stringToLong = s;
}
+
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(UUID uuid) {
+ this.uuid = uuid;
+ }
}