Cache criteria not taken into account when cache option set in mapping
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
The cache setting given inside the criteria:
```
final criteria = Entity.createCriteria()
final result = criteria.list([:]) {
cache(false)
}
```
is overwritten by the setting in the domain mapping:
```
class Entity {
String field1
static mapping = {
cache usage: 'nonstrict-read-write', include: 'all'
}
}
```
Responsible for this behavior is `GrailsHibernateUtil.populateArgumentsForCriteria` method and more specifically `GrailsHibernateUtil.cacheCriteriaByMapping` which looks into domain class mapping and if the cache is enabled there it would set it to true in the criteria. As a workaround I have to use the argument to `list` instead:
```
criteria.list([cache: false]) {
}
```
Thanks
Contributor guide
Research direction
Start with GrailsHibernateUtil.populateArgumentsForCriteria and its cacheCriteriaByMapping method, then trace how criteria.list handles cache(false) versus mapping cache settings. Done means the cache option supplied inside the criteria is not overwritten by the domain mapping, while the existing list argument workaround remains understood through relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100