mirror of https://github.com/apache/openjpa.git
OPENJPA-1814: JPQL fails with Group By and Having aggregate_expression IN (subquery)
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@1003209 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2e62118901
commit
d8782f49ab
|
@ -19,6 +19,8 @@
|
|||
package org.apache.openjpa.kernel;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -29,6 +31,7 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.collections.map.LinkedMap;
|
||||
import org.apache.openjpa.conf.OpenJPAConfiguration;
|
||||
import org.apache.openjpa.kernel.exps.Subquery;
|
||||
import org.apache.openjpa.kernel.exps.AbstractExpressionVisitor;
|
||||
import org.apache.openjpa.kernel.exps.AggregateListener;
|
||||
import org.apache.openjpa.kernel.exps.Constant;
|
||||
|
@ -508,8 +511,28 @@ public class ExpressionStoreQuery
|
|||
for (int i = 0; i < exps.grouping.length; i++)
|
||||
exps.grouping[i].acceptVisit(visitor);
|
||||
visitor._grouping = false;
|
||||
if (exps.having != null)
|
||||
exps.having.acceptVisit(visitor);
|
||||
if (exps.having != null) {
|
||||
Class cls = exps.having.getClass();
|
||||
if (cls.getName().endsWith("Expression"))
|
||||
cls = cls.getSuperclass();
|
||||
Object value2 = null;
|
||||
Method getValue2 = null;
|
||||
try {
|
||||
getValue2 = cls.getMethod("getValue2");
|
||||
getValue2.setAccessible(true);
|
||||
value2 = getValue2.invoke(exps.having, (Object[]) null);
|
||||
} catch (NoSuchMethodException name) {
|
||||
// skip
|
||||
} catch (IllegalAccessException iae) {
|
||||
// skip
|
||||
} catch (InvocationTargetException ite) {
|
||||
// skip
|
||||
}
|
||||
if (value2 != null && value2 instanceof Subquery)
|
||||
; // complex having with subquery, validation is performed by DBMS
|
||||
else
|
||||
exps.having.acceptVisit(visitor);
|
||||
}
|
||||
for (int i = 0; i < exps.projections.length; i++)
|
||||
exps.projections[i].acceptVisit(visitor);
|
||||
}
|
||||
|
|
|
@ -165,6 +165,26 @@ public class TestMultipleEntityProjection extends SingleEMFTestCase {
|
|||
query = em.createQuery(jpql);
|
||||
result = query.getResultList();
|
||||
assertTrue(result.isEmpty());
|
||||
|
||||
// The following JPQL results in syntax error,
|
||||
// see comments in OPENJPA-1814
|
||||
// jpql = "select m.publisher, max(m.datePublished) " +
|
||||
// "from Magazine m group by m.publisher " +
|
||||
// "having max(m.tsPublished) IN " +
|
||||
// "(select max(m.tsPublished) from Magazine m " +
|
||||
// "where m.datePublished = CURRENT_TIMESTAMP)";
|
||||
// query = em.createQuery(jpql);
|
||||
// result = query.getResultList();
|
||||
// assertTrue(result.isEmpty());
|
||||
|
||||
jpql = "select m.publisher, max(m.datePublished) " +
|
||||
"from Magazine m group by m.publisher " +
|
||||
"having max(m.tsPublished) = " +
|
||||
"(select max(m.tsPublished) from Magazine m " +
|
||||
"where m.datePublished = CURRENT_TIMESTAMP)";
|
||||
query = em.createQuery(jpql);
|
||||
result = query.getResultList();
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue