JPA: COUNT broken for subqueries

Bug #765731 reported by Maia Everett on 2011-04-19
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
Undecided
Unassigned

Bug Description

JPASubQuery.count() fails under OpenJPA 2.1.0. It attempts to use COUNT(*), which results in a JPQL error.

Instead, it should use COUNT(path-list), using the list of paths from the query's FROM clause.

Similarly, JPASubQuery.list(path-list).count() fails because it attempts to use COUNT(subquery), which is not allowed. Instead, it should behave as specified.

Fixed in in SVN trunk :

    @Test
    public void Count() {
        assertToString("(select count(cat) from Cat cat)", sub().from(cat).count());
    }

    @Test
    public void Count_Via_List(){
        assertToString("(select count(cat) from Cat cat)", sub().from(cat).list(cat).count());
    }

    @Test
    public void Count_Name() {
        assertToString("(select count(cat.name) from Cat cat)", sub().from(cat).list(cat.name).count());
    }

    @Test
    public void Count_Multiple_Sources() {
        QCat other = new QCat("other");
        assertToString("(select count(cat, other) from Cat cat, Cat other)", sub().from(cat, other).count());
    }

    @Test
    public void Count_Multiple_Sources_Via_List() {
        QCat other = new QCat("other");
        assertToString("(select count(cat, other) from Cat cat, Cat other)", sub().from(cat, other).list(cat, other).count());
    }

Changed in querydsl:
status: New → Fix Committed

Released in 2.2.0-beta4

Changed in querydsl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers