Dynamic finders with InList and OrderBy issue

23 views
Skip to the first unread message

Paul C

unread,
25 Sept 2017, 14:02:4825/09/2017
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,
29 Nov 2017, 07:38:2229/11/2017
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,
23 Jan 2018, 13:26:5323/01/2018
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