mirror of https://github.com/apache/openjpa.git
OPENJPA-1819: if there is a group-by clause, orderby_item must be in the group-by list
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1003317 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1f64b37ec5
commit
a4080f46f5
|
@ -280,13 +280,26 @@ public class SelectConstructor
|
|||
Val orderVal;
|
||||
for (int i = 0; i < exps.ordering.length; i++) {
|
||||
orderVal = (Val) exps.ordering[i];
|
||||
if (contains(orderVal, exps.grouping))
|
||||
state.ordering[i] = orderVal.initialize(sel, ctx, Val.JOIN_REL);
|
||||
else
|
||||
state.ordering[i] = orderVal.initialize(sel, ctx, 0);
|
||||
|
||||
joins = sel.and(joins, state.ordering[i].joins);
|
||||
}
|
||||
}
|
||||
sel.where(joins);
|
||||
}
|
||||
|
||||
private boolean contains(Val orderVal, Value[] grouping) {
|
||||
for (int i = 0; i < grouping.length; i++) {
|
||||
Val groupVal = (Val) grouping[i];
|
||||
if (orderVal.equals(groupVal))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the where sql.
|
||||
*/
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TestEJBQueryInterface extends BaseQueryTest {
|
|||
}
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp(Entity1.class, Entity2.class);
|
||||
super.setUp(Entity1.class, Entity2.class, Order.class, OrderItem.class);
|
||||
|
||||
int instNum = 10;
|
||||
|
||||
|
@ -147,5 +147,16 @@ public class TestEJBQueryInterface extends BaseQueryTest {
|
|||
endEm(em);
|
||||
}
|
||||
|
||||
public void testOrderBy() {
|
||||
EntityManager em = currentEntityManager();
|
||||
startTx(em);
|
||||
String jpql = "SELECT o.oid FROM OrderItem l LEFT JOIN l.order o GROUP BY o.oid ORDER BY o.oid ";
|
||||
try {
|
||||
List ret = em.createQuery(jpql).getResultList();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
//rest of the interface is tested by the CTS
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue