matrei opened a new pull request, #16500:
URL: https://github.com/apache/grails-core/pull/16500
## Description
Fixes five independent bugs in `grails-data-hibernate7` and its BOM. Each
fix and its tests are in their own commit, so they can be reviewed one at a
time.
### `HibernateQuery.add(DetachedCriteria)` left the query unrestricted
The parameter had the same name as the `detachedCriteria` field. The method
therefore added a conjunction of the argument's criteria to the argument
itself, and the query got no restriction. The parameter is renamed.
### `HibernateQuery.add(Junction, Criterion)` ignored the junction
It added the criterion to the first disjunction of the query, creating one
when there was none, and added that disjunction to the query again on every
call. It now adds the criterion to the junction passed in, as
`Query.add(Junction, Criterion)` documents.
This gave wrong results through public GORM API. `CountFinder` builds the
`Or` of `countByXOrY` with `query.disjunction()` and `query.add(disjunction,
criterion)`. Called on a where query with an `or` block, the `Or` terms went
into the where query's `or` block instead:
```groovy
Person.where {
or {
eq('lastName', 'Builder')
eq('lastName', 'Rogers')
}
}.countByFirstNameOrAge('Walt', 51) // returned 0, now 1
```
### `eq(property, value, [ignoreCase: true])` was a substring match
In a Hibernate 7 criteria query it was translated to a case-sensitive `like
'%value%'`. It matched any value containing the text in the same case, treated
`%` and `_` in the value as wildcards, and did not match a value that differed
only in case. That contradicts the `createCriteria` reference, which describes
it as a case-insensitive `eq`.
It now compares the property in lower case with the value in lower case, as
GORM for Hibernate 5 does. A property or value that is not a `String` is
compared with plain equality. The translation uses a new criterion,
`EqualsIgnoreCase`, which `HibernateQuery.eqIgnoreCase(property, value)` adds.
### `GrailsHibernateTemplate.lock(entity, lockMode)` ignored `lockMode`
It always locked with `PESSIMISTIC_WRITE`. It now locks with the mode it is
given, as the Hibernate 5 template does. Every internal caller passes
`PESSIMISTIC_WRITE`, so only code calling the template directly is affected.
### `grails-hibernate7-bom` managed an unpublished `liquibase-hibernate7`
version
The BOM constrained `org.liquibase.ext:liquibase-hibernate7` to `4.27.0`,
which was never published. Maven Central has only 5.0.x. An application adding
the artifact without a version could not resolve it. No Grails module uses the
artifact: the Hibernate 7 database migration plugin includes its own copy of
the Liquibase Hibernate extension, so the artifact would put a second copy of
the same classes on the classpath. The constraint and its version key are
removed, and the Dependency Versions reference now says why the Hibernate 7 BOM
does not manage it.
### Tests
- `HibernateQuerySpec`: `addDetachedCriteria` and `addJunctionCriterion` are
rewritten. They passed only because the table held one row, or because the
junction they passed was not attached to the query. New tests cover a criterion
added to the second of two disjunctions, a criterion added to a conjunction,
the `countByFirstNameOrAge` case above and `eqIgnoreCase`.
- `HibernateCriteriaBuilderDirectSpec`: the `ignoreCase` test asserted the
substring behaviour. It now checks whole-value matching in any case, that `%`
is not a wildcard, the `eq(Map, property, value)` overload, `ignoreCase:
false`, a non-`String` value and an association block.
- `PredicateGeneratorSpec`: executes `EqualsIgnoreCase` on a `String` and an
`Integer` property.
- `GrailsHibernateTemplateSpec`: `lock` with `PESSIMISTIC_READ` and
`PESSIMISTIC_WRITE` applies that lock mode.
Without the fixes, all of these tests fail except the one for
`eqIgnoreCase`, a new method that the old code doesn't have. All 3487 tests of
`:grails-data-hibernate7-core:test` pass.
`:grails-hibernate7-bom:validateBomProperties`, `checkstyleMain` and
`codenarcMain` pass.
--
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]