borinquenkid commented on PR #16823:
URL: https://github.com/apache/grails-core/pull/16823#issuecomment-6579280518
**For the team: criteria `get` with several matching rows**
This PR now fails a criteria `get` when more than one row matches, as
Hibernate 5 does. Before, Hibernate 7 caught the error and returned the first
row.
The criteria reference describes `get` as returning "a unique result, i.e.
just one row… not to be confused with a limit to just the first row". On H5,
`createCriteria().get { gt 'qty', 0 }` over three rows throws
`NonUniqueResultException`; on H7 it returned the first. An application that
relied on H5's error to find a criteria matching too much would stop seeing it
after an upgrade.
`find`, `findBy*`, `findWhere` and the `get()` and `find()` of a `where`
query return the first row on both modules, and still do. One integration spec
(`CriteriaSingleResultScenarioSpec`) runs unchanged on the H5 and H7
`grails-hibernate` apps: H5 7/7, H7 7/7.
**Worth sharing with the team**
- The docs list `singleResult` as an alias for `get`, but H5 has no such
method (`MissingMethodException`). H7 has it and returns the first row. I left
it as it is; making it strict would turn an H5 error into a different H7
behavior.
- A criteria that sets `maxResults` still returns a row and does not throw,
on both modules.
--
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]