grails-data-mapping
grails-data-mapping copied to clipboard
Dynamic finders with InList and OrderBy issue
This is being submitted as a bug because it should either report an error or work. Instead it silently ignores the OrderByPath suffix
Steps to Reproduce
- Using a normal grails domain object with postgres 5.x, include both Inlist and OrderBy
def allLocations = Location.findAllByIdInListOrderByPath(locationArray)
- Enable show_sql in application.yml
hibernate:
...
show_sql: true
logSql: true
- Check log output for 'order by' in generated SQL
Expected Behaviour
Hibernate SQL should have an 'order by' clause or it should generate an exception if invalid (not sure if OrderBy is supported for InList).
Actual Behaviour
OrderBy is ignored
Environment Information
- Operating System: Linux and Windows 7
- Grails Version: 3.2.9 compile 'org.grails.plugins:postgresql-extensions:5.0.0' compile "org.grails.plugins:hibernate5" compile "org.hibernate:hibernate-core:5.1.6.Final" compile "org.hibernate:hibernate-ehcache:5.1.6.Final"
- JDK Version: 1.8
- Container Version (If Applicable): N/A
Hibernate SQL should have an 'order by' clause or it should generate an exception if invalid
Agreed.
Are there docs anywhere for recent versions of GORM that suggest it should work?
Grails support for listOrderBy suggests it is possible: http://docs.grails.org/3.1.1/ref/Domain%20Classes/listOrderBy.html
Howerver, it is not explicitly mentioned in hibernate GORM doc: http://gorm.grails.org/latest/hibernate/manual/#querying
Since Spring repository supports a variation of orderBy maybe I assumed GORM did too.
Is it supported? Regardless, it raises the more important issue that it should fail at compile time and if that is not possible it should throw a runtime exception.
it should fail at compile time and if that is not possible it should throw a runtime exception
It is possible to fail dynamic finders at compile time but that does not currently happen. Invalid dynamic finder names are currently dealt with at runtime.
By the code, orderBy feature not supported for dynamic finders, only by list function. As work around sort parameter can be used. Location.findAllByIdInList(locationArray, [sort:'path'])
Not a bug?