Dynamic finders with InList and OrderBy issue

23 views
Skip to first unread message

Paul C

unread,
Sep 25, 2017, 2:02:48 PM9/25/17
to Grails Dev Discuss
Here is a query  where I thought the OrderBy suffix would work but the generated SQL does not have an order by.  

Any insight on what happened here is greatly appreciated.  I thought it would at least cause an error if the context is not valid for OrderBy.  We are using several recent versions of postgres.


def allLocations = Location.findAllByIdInListOrderByPath(locationArray)

Notice hibernate sql does not have 'order by':

Hibernate:
    /* criteria query */ select
        this_.id as id1_20_0_,
        ...
        this_.path as path8_20_0_,
        ...
    from
        location this_
    where
        this_.id in (
            ?, ?, ?, ?, ?, ?
        )

David Estes

unread,
Nov 29, 2017, 7:38:22 AM11/29/17
to Grails Dev Discuss
Remove the OrderBy and I believe you can pass a map as a method arg to the dynamic finder with properties sort and direction

Dem K

unread,
Jan 23, 2018, 1:26:53 PM1/23/18
to Grails Dev Discuss
Rather use a Criteria, much better fine grain control

http://docs.grails.org/3.1.1/guide/single.html#criteria

def c = Account.createCriteria()
def results = c {
    between("balance", 500, 1000)
    eq("branch", "London")
    or {
        like("holderFirstName", "Fred%")
        like("holderFirstName", "Barney%")
    }
    maxResults(10)
    order("holderLastName", "desc")
}

Reply all
Reply to author
Forward
0 new messages