Fix @InsertOnlyProperty handling for embedded properties - #2367
Open
alpin87 wants to merge 1 commit into
Open
Conversation
Insert-only columns contributed by embedded properties were not excluded from the SET clause. R2dbcEntityTemplate collected insert-only columns by iterating the top-level entity properties, so an annotated embedded container contributed its container name instead of its expanded leaf columns, and annotated properties inside an embeddable were never visited. The JDBC SqlGenerator handled leaf-annotated properties but did not propagate an annotated container to the columns it contributes. Collect insert-only columns by expanding embedded properties in R2dbcEntityTemplate, used by both the update and the upsert path, and propagate the container's insert-only flag through the embedded recursion in SqlGenerator's column-name cache. Closes spring-projects#2366 Signed-off-by: seungmin <qortmdals94@naver.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2366
@InsertOnlyPropertywas silently ignored when combined with@Embedded, so insert-only columns (the typical case being creation-audit fields grouped in an embeddable) were overwritten on every update.What was broken
R2dbcEntityTemplatecollected insert-only columns by iterating the top-level entity properties. An annotated embedded container contributed its container name (not a real column of the outbound row, which holds the expanded, prefixed leaf columns), and an annotated property inside an embeddable was never visited. Both the update path and the upsert path'sinsertOnlyColumnscollection (added in R2dbcEntityTemplate.upsert() generates invalid SQL for entities with @Embedded.Empty composite primary keys #2313 / fc94989) were affected.On the JDBC side,
SqlGeneratorhandled leaf-annotated properties correctly (its column-cache recursion reads each leaf'sisInsertOnly()), but an annotated container was not propagated to the columns it contributes. Verified with a test before the fix:So the leaf-annotated gap was R2DBC-specific, while the container-annotated gap affected both modules (also noted on the issue).
Fix
R2dbcEntityTemplate: a private helper collects insert-only column names by expanding embedded properties throughRelationalMappingContext#getRequiredPersistentEntity(RelationalPersistentProperty)— the same recursionDefaultReactiveDataAccessStrategy#getAllColumnsalready uses (the cast toRelationalMappingContextmirrors that class as well). Properties inside an insert-only container are treated as insert-only. Used by both the update and the upsert path.SqlGenerator(JDBC): the embedded recursion in the column-name cache now propagates the container's insert-only flag, so leaf columns of an insert-only embedded land ininsertOnlyColumnNamesand are excluded from the updatable columns.Tests
Five new tests, all failing before the fix and passing after:
R2dbcEntityTemplateUnitTests: update excludes insert-only embedded container columns / insert-only properties inside an embeddable (exact-SQL assertions in the style ofupdateExcludesInsertOnlyColumns)ReactiveUpsertOperationUnitTests: theDO UPDATE SETclause no longer touches insert-only embedded columnsSqlGeneratorUnitTests: JDBC update SQL excludes container-contributed insert-only columns; leaf-annotated exclusion kept as a regression guardFull
spring-data-jdbcandspring-data-r2dbctest suites pass.