skaz skaz - 2 years ago 103
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 asc"
return executeQuery(sql, [affiliation: this])

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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download