mirror of https://github.com/apache/openjpa.git
OPENJPA-1715: OpenJPA generates wrong SQL if a result variable that references an aggregate expression is used in ORDER BY clause
add testcase. git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@961449 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ae5c2c881e
commit
d7a9cdf3de
|
@ -20,6 +20,7 @@ package org.apache.openjpa.persistence.jpql.expressions;
|
|||
|
||||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.apache.openjpa.persistence.common.apps.*;
|
||||
import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
|
||||
|
@ -69,6 +70,22 @@ public class TestJPQLScalarExpressions extends AbstractTestCase {
|
|||
endEm(em);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAggregateResultVariable() {
|
||||
EntityManager em = currentEntityManager();
|
||||
String querys[] = {
|
||||
"SELECT c.name as name, SUM(c.age) as sage FROM CompUser c group by c.name order by sage desc, name",
|
||||
"SELECT c.name, AVG(c.age) as age FROM CompUser c group by c.name order by age desc, c.name",
|
||||
};
|
||||
for (int i = 0; i < querys.length; i++) {
|
||||
Query query = em.createQuery(querys[i]);
|
||||
query.setFirstResult(1);
|
||||
query.setMaxResults(4);
|
||||
List<Object[]> rs = query.getResultList();
|
||||
assertTrue((Long)((Object[]) rs.get(0))[1] > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMathAndAggregate() {
|
||||
EntityManager em = currentEntityManager();
|
||||
|
|
Loading…
Reference in New Issue