Skip to content

Conversation

@schauder
Copy link
Contributor

Delete operations that receive a version attribute throw an OptimisticFailureException when they delete zero rows.
Otherwise, the NOOP delete gets silently ignored.

Note that save operations that are determined to be an update because the aggregate is not new will still throw an IncorrectUpdateSemanticsDataAccessException if they fail to update any row.
This is somewhat asymmetric to the delete-behaviour.
But with a delete the intended result is achieved: the aggregate is gone from the database.
For save operations the intended result is not achieved, hence the exception.

Closes #1313

…epository.

Delete operations that receive a version attribute throw an `OptimisticFailureException` when they delete zero rows.
Otherwise, the NOOP delete gets silently ignored.

Note that save operations that are determined to be an update because the aggregate is not new will still throw an `IncorrectUpdateSemanticsDataAccessException` if they fail to update any row.
This is somewhat asymmetric to the delete-behaviour.
But with a delete the intended result is achieved: the aggregate is gone from the database.
For save operations the intended result is not achieved, hence the exception.

Closes #1313
See spring-projects/spring-data-commons#2651
@schauder schauder requested review from gregturn and mp911de August 25, 2022 14:20
* @param instances the aggregate roots to be saved. Must not be {@code null}.
* @param <T> the type of the aggregate root.
* @return the saved instances.
* @throws IncorrectUpdateSemanticsDataAccessException when at least one instance is determined to be not new and the
Copy link
Member

Choose a reason for hiding this comment

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

Would JdbcUpdateAffectedIncorrectNumberOfRowsException be the right one to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably yes.

Copy link
Member

Choose a reason for hiding this comment

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

We still can define IncorrectUpdateSemanticsDataAccessException here, I was just wondering that we have no code changes associed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When going through the test I noted this behaviour, wondered if it is the correct one, which I think it is and documented it to make things nice and tidy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just looked into changing the actual exception thrown into a JdbcUpdateAffectedIncorrectNumberOfRowsException. It would require passing a SQL statement and an expected and actual number of updated rows to the constructor. This seems like the wrong abstraction level to me and I'd rather keep the IncorrectUpdateSemanticsDataAccessException.

@mp911de
Copy link
Member

mp911de commented Aug 25, 2022

On a general level, why do we define delete(T aggregateRoot, Class<T> domainType) (i.e. passing on the domain type) instead of determining the domain type from the aggregateRoot object? Other methods follow a similar design.

@schauder
Copy link
Contributor Author

On a general level, why do we define delete(T aggregateRoot, Class<T> domainType) (i.e. passing on the domain type) instead of determining the domain type from the aggregateRoot object? Other methods follow a similar design.

Early design mistake by an old junior developer? I'll create a separate issue to fix that.

@mp911de
Copy link
Member

mp911de commented Aug 25, 2022

Regarding the methods, we could clean up the interface for 3.0 and leave the methods accepting the type on the actual implementation to simplify the migration of external code.

@mp911de mp911de added the type: enhancement A general enhancement label Aug 31, 2022
mp911de pushed a commit that referenced this pull request Aug 31, 2022
…epository`.

Delete operations that receive a version attribute throw an `OptimisticFailureException` when they delete zero rows.
Otherwise, the NOOP delete gets silently ignored.

Note that save operations that are determined to be an update because the aggregate is not new will still throw an `IncorrectUpdateSemanticsDataAccessException` if they fail to update any row.
This is somewhat asymmetric to the delete-behaviour.
But with a delete the intended result is achieved: the aggregate is gone from the database.
For save operations the intended result is not achieved, hence the exception.

Closes #1313
Original pull request: #1314.
See spring-projects/spring-data-commons#2651
mp911de pushed a commit that referenced this pull request Aug 31, 2022
…epository`.

Delete operations that receive a version attribute throw an `OptimisticFailureException` when they delete zero rows.
Otherwise, the NOOP delete gets silently ignored.

Note that save operations that are determined to be an update because the aggregate is not new will still throw an `IncorrectUpdateSemanticsDataAccessException` if they fail to update any row.
This is somewhat asymmetric to the delete-behaviour.
But with a delete the intended result is achieved: the aggregate is gone from the database.
For save operations the intended result is not achieved, hence the exception.

Closes #1313
Original pull request: #1314.
See spring-projects/spring-data-commons#2651
@mp911de mp911de added this to the 2.4.3 (2021.2.3) milestone Aug 31, 2022
@mp911de
Copy link
Member

mp911de commented Aug 31, 2022

That's merged and backported now.

@mp911de mp911de closed this Aug 31, 2022
@schauder schauder deleted the issue/1313-noop-deletes branch March 30, 2023 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Correct behaviour of NOOP deletes to match the specification in CrudRepository

3 participants