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

Omit sequence generation for non-new entities and entities with provided identifiers #2005

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mipo256
Copy link
Contributor

@mipo256 mipo256 commented Mar 4, 2025

Closes #2003

Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

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

Thanks for having a look. Formatting is terribly off. Please make sure to use the formatting config (and import style) at https://github.com/spring-projects/spring-data-build/tree/main/etc/ide.

I left quite a few comments given that this is quite a sized PR touching up on many aspects. Let me know if you require more detail and whether my feedback is too short at places.

Object identifier = persistentEntity.getIdentifierAccessor(aggregate).getIdentifier();

if (persistentEntity.getIdProperty().getType().isPrimitive()) {
return identifier instanceof Number num && num.longValue() != 0L;
Copy link
Member

Choose a reason for hiding this comment

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

Notice to myself: We should introduce an utility to determine whether a primitive is set to its initial value.

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 can introduce it in separate commit in the same PR, it seems that it is natural to do it in the context of the current ticket. What do you think @mp911de ?

Copy link
Member

Choose a reason for hiding this comment

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

I was considering an utility in Spring Data Commons. Let me verify whether this is a good idea or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll wait for your response. I think I can help with this as well.


@BeforeEach
void setUp() {
auditableNamedParameterJdbcTemplate.clearRecordedStatements();
Copy link
Member

Choose a reason for hiding this comment

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

When already having an integration test, it doesn't make much sense to verify against statements. Rather, we should the result.

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'm sorry, but it does not seem to be clear for me how we can verify the SELECT statements executed to query the sequence. We can create a wrapper around ID generating callback and try to utilize it. I am not sure which approach is better to be honest @mp911de

Copy link
Member

Choose a reason for hiding this comment

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

There's a blog post by Vlad on verifying and counting statements see https://vladmihalcea.com/how-to-detect-the-n-plus-one-query-problem-during-testing/

I think that one can serve as input for decorating our data sources to be tested.

@mp911de mp911de changed the title GH-2003 ID generation via Sequence should be omitted in UPDATE queries Omit sequence generation for non-new entities and entities with provided identifiers Mar 4, 2025
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 4, 2025
@mp911de mp911de self-assigned this Mar 4, 2025
@mipo256
Copy link
Contributor Author

mipo256 commented Mar 4, 2025

Hey @mp911de! Thanks for review :)

Yeah, I forgot to ask about formatting, my bad, I'll fix it ASAP

@mipo256
Copy link
Contributor Author

mipo256 commented Mar 7, 2025

Hey @mp911de! I've fixed almost all comments left, but several comments I've left open for discussion since it is not clear for me what needs to be done

@mp911de
Copy link
Member

mp911de commented Mar 19, 2025

@mipo256 I'd like to come back to this one. I think the only remaining issue is AuditableNamedParameterJdbcTemplate. Please remove that one for the time being in favor of verifying target sequences and entities after the test run for assertions.

@mp911de mp911de added this to the 3.5 RC1 (2025.0.0) milestone Mar 19, 2025
@mipo256
Copy link
Contributor Author

mipo256 commented Mar 19, 2025

Hey @mp911de! I understand that it is coming into the RC, I'll resolve it very shortly. Thank you! I'll tag you once the remaining stuff is fixed

@mipo256
Copy link
Contributor Author

mipo256 commented Mar 19, 2025

Regarding the article from Vlad you've proposed, Mark @mp911de.

The problem is that this article also utilizes the external library for proxying the DataSource. And Vlad is also using custom listeners, defined in the hypersistence project.

Let me just clarify - for now, do we want to actually bring any of those libraries into the project, or do we want to just get rid of AuditableNamedParameterJdbcTemplate and be done with it? I think we eventually need the solution for tracking the queries executed.

P.S: That comments thread remained unanswered. I can create an issue, it seems that it fits more in commons module, what do you think?

@mp911de
Copy link
Member

mp911de commented Mar 19, 2025

The problem is that this article also utilizes the external library for proxying the DataSource. And Vlad is also using custom listeners, defined in the hypersistence project.

DataSource Proxy wouldn't be an issue, however, custom listeners are. So for the time being, let's verify target sequences and entities after the test run for assertions.

Re Util for primitive values: I'll handle that during the merge.

@mipo256
Copy link
Contributor Author

mipo256 commented Mar 19, 2025

Done @mp911de, can you re-review please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@Sequence Annotation generates a new Id on update
3 participants