Grails CreateCriteria Select disitinct over from Table

324 Views Asked by At

I use grails 2.5.6 with IntelliJ IDEA 2017.2.4

I have a problem with my criteria

Book.createCriteria().listDistinct{
    person{
        address{
            eq("id", 5)
        }
    }
}

How can I write a projection of the Book

Normal criteria create a SQL with:

SELECT DISTINCT * FROM book AS b INNER JOIN ....

But I need a SQL like this:

SELECT DISTINCT b.* FROM book AS b

How can I realize this projection in the createCriteria? Or should I use a subselect with criteria?
(I dont want to use HQL)


Thanks, Marvin

My Classes:

class Book{
    //other stuff
    static hasMany = [person: Person]
}

class Person{
    //other stuff
    static hasMany=[address: Address]
}

class Address{
    //other stuff
}
0

There are 0 best solutions below