Repository navigation
feat(gorm): the criteria closures of the static GORM API type-check under CompileStatic - #17080
borinquenkid wants to merge 1 commit into
Conversation
…nder CompileStatic where, whereLazy, whereAny and findAll take a closure that is annotated with DelegatesTo(DetachedCriteria), so eq, gt and the other criteria methods type-check inside CompileStatic code. No result changes. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A nested query attaches its condition to the outer query.
| */ | ||
| @Generated | ||
| static DetachedCriteria<D> where(Closure callable) { | ||
| static DetachedCriteria<D> where(@DelegatesTo(DetachedCriteria) Closure callable) { |
There was a problem hiding this comment.
A where query on one class contains a where query on another, and the inner query calls eq. That eq should restrict the inner query. It restricts the outer query, so the inner query matches every row. Resolve the call on the inner query first.
|
Agree with James on this one. I think the cause is the missing strategy on the annotation. Using Small side note: |
@DelegatesTopart of #16823 (item 5 of matrei's review), on 8.1.x: it lets code that did not compile before compile, so it is an improvement for the next minor, not a fix for a patch line.Part of #16808
The change
The closures of
where,whereLazy,whereAnyand bothfindAlloverloads onGormEntityare annotated with@DelegatesTo(DetachedCriteria), soeq,gtand the other criteria methods type-check inside plain@CompileStaticcode instead of needing@CompileDynamic.GormEntityis ingrails-datamapping-core, so every datastore gets it. No result changes: code that compiled before runs as it did.What changes for applications
Nothing has to change. Code that used
@CompileDynamiconly for these calls can drop it. The upgrade guide has a note in the Grails 8.1.0 section.Tests
GormEntityCriteriaTypingSpec(Hibernate 7): the flat criteria of the five calls under plain@CompileStatic(the spec does not compile without the annotations), and where closures under@GrailsCompileStaticwith an association block, a path and a mix, which return the rows of the association rather than binding the call to the outer criteria. The fullgrails-datamapping-coreandgrails-data-hibernate7-coresuites pass.https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL