dvkvarma opened a new issue, #14457:
URL: https://github.com/apache/grails-core/issues/14457
When we configure hasMany property to be sorted by a sub-property, its
throwing an NPE. This confguration was working fine in grails-2.
```groovy
class Person {
String firstName
String lastName
static hasMany = [devices: PersonDevice]
static mapping = [
devices cascade: 'all-delete-orphan', sort: 'device.priority'
]
}
class Device {
String name
Integer priority
}
class PersonDevice {
Device device
Date purchaseDate
}
```
Here i would like sort the **person.devices** by **device.priority**.
Getting the following exception on grails app startup.
```
Caused by: java.lang.NullPointerException: null
at
org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindCollectionSecondPass(GrailsDomainBinder.java:372)
at
org.grails.orm.hibernate.cfg.GrailsDomainBinder$GrailsCollectionSecondPass.doSecondPass(GrailsDomainBinder.java:3399)
at
org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1631)
at
org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1599)
```
I suggest to do the following:
- Add a defensive null check against the propertyToSortBy and throw an
appropriate error.
- Add support for sorting by the properties of the relation.
**propertyToSortBy** is returned as null, as it is looking up property by
name.
https://github.com/grails/gorm-hibernate5/blob/62ba190ee385b99f8a4e551790506dbf235a000b/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java#L362
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]