Repository navigation
fix(hibernate7): query arguments reach criteria queries and a criteria get is unique - #17077
borinquenkid wants to merge 4 commits into
Conversation
…a get is unique readOnly, fetchSize, timeout and flushMode were dropped by criteria queries, where queries and dynamic finders. QueryArgumentsAware is implemented by HibernateQuery, a criteria get throws when several rows match, and a criteria call that throws closes the session it opened. No public API is added: the settings record and the cleanup hook are package-private. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A criteria get of one row can return a proxy that a cast used to accept.
| if (rows.size() > 1) { | ||
| throw new NonUniqueResultException(rows.size()); | ||
| } | ||
| result = rows.isEmpty() ? null : rows.get(0); |
There was a problem hiding this comment.
The session already holds a proxy of the base class for the one matching subclass row. get used to unwrap that proxy. It now returns the proxy, so a cast to the subclass fails. Unwrap the one row before returning it.
… mode and the timeout of the query arguments Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
@jamesfredley: the same finding you made on the Hibernate 5 pull request was open here. I ran every query setting through every paged route on Hibernate 7 ( |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #17077 +/- ##
================================================
+ Coverage 0 62.5796% +62.5796%
- Complexity 0 27545 +27545
================================================
Files 0 2249 +2249
Lines 0 111725 +111725
Branches 0 20486 +20486
================================================
+ Hits 0 69917 +69917
- Misses 0 32450 +32450
- Partials 0 9358 +9358 🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 45c199c Learn more about TestLens at testlens.app/docs. |
Hibernate 7 part of #16823, rebased on 8.0.x on its own, with no new public API. The Hibernate 5 part (7.0.x) and
@DelegatesTo(8.1.x) follow as separate pull requests.Part of #16808
The bug
With Hibernate 7,
readOnly,fetchSize,timeoutandflushModereach HQL queries but not criteria queries:where { }.list(readOnly: true),find,findAll(args) { }, finders with a map andwithCriteria(args)all ignored them, andcreateCriteria().list(args)ignored them too.createCriteria().get { }returned the first of several matching rows instead of the unique result the reference describes (Hibernate 5 throws). A criteria call that threw left its session bound.The change
HibernateQueryimplements the existingQueryArgumentsAware, whichDynamicFinderandDetachedCriteriaalready call;HibernateQuerySettings(package-private) parses the arguments for the criteria and HQL paths alike. AfetchSizeortimeoutthat is not a whole number throws anIllegalArgumentExceptionnaming the argument.gettakes the rows fromlist()and throwsNonUniqueResultExceptionfor several,nullfor none.CriteriaMethodInvokercloses the session the builder opened when the call throws, and leaves a caller's session alone.No public class or method is added: the settings record and the cleanup hook are package-private, and the criteria
getuses the existinglist().What changes for applications
Arguments that criteria queries and finders ignored now apply; a criteria
getthat returned the first of several rows now throws (the note shows how to keep the first row with anorderandmaxResults(1)); afetchSizeortimeoutthat is not a whole number throws. The upgrade note is in the Grails 8.0.1 section, thegrails-upgradeskill has an entry. This changes a result, so it needs two reviewers.Tests
QueryArgumentsPropagationSpec(9 features, 6 fail whensetArgumentsdoes nothing),CriteriaSessionCleanupSpec,HibernateQuerySettingsSpec,HibernateQueryExecutorSpecandCriteriaMethodInvokerSpec.CriteriaQueryArgsScenarioSpecandCriteriaSingleResultScenarioSpec, on a domain class of their own (CriteriaItem). The scenarios that return one of several rows no longer assume an order.grails-data-hibernate7-coresuite passes.https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL