Repository navigation
Exclude composite identifier columns from the UPDATE SET clause - #2407
Open
sharanggupta wants to merge 1 commit into
Open
sharanggupta wants to merge 1 commit into
sharanggupta wants to merge 1 commit into
Conversation
The column cache in SqlGenerator.Columns decided whether a column belongs to the identifier by asking the property's owner. For a composite identifier the owner of each column is the identifier type itself, which carries no @id annotation of its own, so every column of the composite identifier was classified as a regular column and ended up in the SET clause of the generated UPDATE statement in addition to the WHERE clause. Databases that reject assignments to primary key columns fail the statement, which makes save() unusable for aggregates with a composite identifier. The traversal of embedded entities now carries the attributes a property inherits from the properties enclosing it, namely the column prefix, whether it is reached through an insert-only property and whether it is part of the identifier, in a single Nesting value. Columns reached through the @id property are registered as identifier columns and therefore excluded from the SET clause, while the WHERE clause and the INSERT statement, which already obtain the identifier columns from the parameter source, are unchanged. Closes spring-projects#2338 Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
This branch has not been deployed
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 #2338
For an aggregate whose
@Idis a composite identifier,SqlGenerator.Columnsclassified the identifier's columns as regular columns because it asked the property's owner (the identifier type itself, which has no@Idof its own) whether the property is the id. The columns consequently appeared in theSETclause of the generatedUPDATEin addition to theWHEREclause, which fails on databases that reject assignments to primary key columns (the YDB dialect currently works around this downstream in ydb-platform/ydb-java-dialects#241).The column walk now carries the attributes a property inherits from its enclosing properties (column prefix, insert-only, part of the identifier) in one small
Nestingvalue instead of two parallel parameters, so columns reached through the@Idproperty are registered as identifier columns and excluded fromSET.WHEREandINSERTare unchanged; the latter already receives the identifier columns from the parameter source. If you would rather keep the existing parameter style and just thread an additional flag, I am happy to change it.Unit tests cover both declaration forms (
@Id EmployeeId idinSqlGeneratorUnitTests,@Id @Embedded EmbeddedIdinSqlGeneratorEmbeddedUnitTests); both fail onmain. Thespring-data-jdbcunit suite (590 tests) and the HSQL composite-id and embedded integration tests pass.