Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip insert/update for @GeneratedValue annotated fields in @Embedded #3344

Merged
merged 8 commits into from
Mar 18, 2025

Conversation

radovanradic
Copy link
Contributor

This should fix issue

@radovanradic radovanradic requested a review from dstepanov March 5, 2025 13:24
@@ -791,6 +791,13 @@ public JsonDataType getJsonDataType() {
QueryPropertyPath propertyPath = entry.getKey();
if (entry.getValue() instanceof BindingParameter bindingParameter) {
PersistentEntityUtils.traversePersistentProperties(propertyPath.getPropertyPath(), traverseEmbedded(), (associations, property) -> {

boolean generated = PersistentEntityUtils.isPropertyGenerated(entity,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is code that filters persistent properties before building update query, but one of these are embedded and we need to check each fields inside embedded here.

@@ -1026,7 +1027,8 @@ public int getParameterIndex() {

for (PersistentProperty prop : persistentProperties) {
traversePersistentProperties(prop, (associations, property) -> {
if (prop.isGenerated()) {
boolean generated = PersistentEntityUtils.isPropertyGenerated(entity, prop, property);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow fix the prop.isGenerated to return true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not look like. We have for example Author(id) which is generated in context of Author entity insert/update. But, when doing Book insert/update then it is not generated and it needs to be updatable. This is why we need more context to check if field is generated ie. involved in insert/update.

@@ -861,7 +861,8 @@ public JsonDataType getJsonDataType() {

for (PersistentProperty prop : persistentProperties) {
PersistentEntityUtils.traversePersistentProperties(Collections.emptyList(), prop, (associations, property) -> {
if (prop.isGenerated()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this check was not valid
if (prop.isGenerated()) {
because prop is property being traversed (either single property or association) and I think we should check property that is result of prop traversal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right

@radovanradic radovanradic changed the base branch from 4.11.x to 4.12.x March 17, 2025 09:29
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
40.0% Duplication on New Code (required ≤ 10%)

See analysis details on SonarQube Cloud

@radovanradic radovanradic added the type: bug Something isn't working label Mar 18, 2025
@radovanradic radovanradic merged commit 59e5d4c into 4.12.x Mar 18, 2025
53 of 54 checks passed
@radovanradic radovanradic deleted the generated-embedded branch March 18, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Annotation @GeneratedValue is ignored inside @Embedded
2 participants