skaz skaz - 7 months ago 22
SQL Question

Grails Order By Not Working

I have a Grails query that has an order by clause, but when the results come back they are not ordered by that field. If I run the same query in the database it works correctly.

String sql = "select child From Affiliation a join a.childrenPhases cp join cp.affiliation child where a = :affiliation and child.type = '${TYPE_CONFERENCE}' order by a.name asc"
return executeQuery(sql, [affiliation: this])


name
off of
a
is a hibernate formula field. Could this have to do with it? Thanks.

Answer

The best way to troubleshoot a problem like this is to dump the SQL generated by hibernate. Add the following to your DataSource.groovy:

loggingSql = true