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

Bug: different behaviour between save(save(x)), and save(find(save(x))) #859

Closed
fedpet opened this issue May 8, 2024 · 3 comments
Closed

Comments

@fedpet
Copy link

fedpet commented May 8, 2024

this code

x = repository.save(x);
x = repository.findById(x.id)
x = repository.save(x);

behaves the expected way, while this one:

x = repository.save(x);
x = repository.save(x);

will generate an update query that tries to set all fields, even untouched null fields.

So imagine you have a COLUMN c NOT NULL DEFAULT 'bla'. The first example will correctly leave c to default since it's never touched. Se second example will unexpectedly try to update c and set it to null, and the DB will throw an exception.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 8, 2024
@mp911de
Copy link
Member

mp911de commented May 8, 2024

This is expected as calling save once inserts the object, the second call yields an update as the identifier is populated.

We do not track dirty state and we do not insert null fields. For the update case, we must provide null values to the update to reflect the entity state in the database as we do not track any changes.

Another aspect here is that we do only retrieve the generated identifier. Any default values that come from the database aren't transmitted back by the insert statement. So if you generate values in your database and want to see these, then load-after-save is the only viable approach.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label May 8, 2024
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label May 15, 2024
@spring-projects-issues
Copy link

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants