Test that reproduces the clause analysis for expressions misses joins coming from subqueries
@@ -550,4 +550,26 @@ public class PaginationTest extends AbstractCoreTest {
assertEquals(objectQuery, cb.getQueryString());
cb.getResultList();
}
+
+ @Test
+ // Test for issue #420
+ public void testPaginationWithJoinFromSelectSubquery() {
+ PaginatedCriteriaBuilder<Tuple> cb = cbf.create(em, Tuple.class).from(Document.class, "d")
+ .selectSubquery()
+ .from(Person.class, "pSub")
+ .where("pSub.id").eqExpression("OUTER(contacts.id)")
+ .end()
+ .orderByAsc("d.id")
+ .page(0, 10);
+
+ String countQuery = "SELECT " + countPaginated("d.id", true) + " FROM Document d LEFT JOIN d.contacts contacts_1";
+ String idQuery = "SELECT d.id FROM Document d LEFT JOIN d.contacts contacts_1" +
+ " GROUP BY " + groupBy("d.id", renderNullPrecedenceGroupBy("d.id")) + " ORDER BY " + renderNullPrecedence("d.id", "ASC", "LAST");
+ String objectQuery = "SELECT (SELECT pSub FROM Person pSub WHERE pSub.id = " + joinAliasValue("contacts_1", "id") + ") FROM Document d LEFT JOIN d.contacts contacts_1" +
+ " WHERE d.id IN :ids ORDER BY " + renderNullPrecedence("d.id", "ASC", "LAST");
+ assertEquals(countQuery, cb.getPageCountQueryString());
+ assertEquals(idQuery, cb.getPageIdQueryString());
+ assertEquals(objectQuery, cb.getQueryString());
+ cb.getResultList();
+ }
}
