grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

Dynamic finders with InList and OrderBy issue

Open pkcinna01 opened this issue 7 years ago • 4 comments

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

  1. Using a normal grails domain object with postgres 5.x, include both Inlist and OrderBy def allLocations = Location.findAllByIdInListOrderByPath(locationArray)
  2. Enable show_sql in application.yml
hibernate:
    ...
    show_sql: true
    logSql: true
  1. 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

pkcinna01 avatar Sep 26 '17 12:09 pkcinna01

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?

jeffscottbrown avatar Sep 26 '17 14:09 jeffscottbrown

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.

pkcinna01 avatar Sep 26 '17 17:09 pkcinna01

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.

jeffscottbrown avatar Sep 26 '17 17:09 jeffscottbrown

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?

demon101 avatar Feb 21 '19 13:02 demon101