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

Missing implicite entityManager.flush() before storedprocedure call and Spring-Data Repository #3433

Closed
ere-one opened this issue Apr 17, 2024 · 2 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: declined A suggestion or change that we don't feel we should currently apply

Comments

@ere-one
Copy link

ere-one commented Apr 17, 2024

I have an Spring Data JPA Repository with a StoreProcedure caller method, annotated with @procedure.
I made some changes on entities which are attached to the entityManager.
If i call the StoredProcedure method without explicitly calling entityManager.flush() first, the StoredProcedure does not see the changes.

Issue is also described here:
https://stackoverflow.com/questions/53839795/how-to-flush-spring-data-jpa-before-calling-stored-procedure

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 17, 2024
@christophstrobl christophstrobl added status: declined A suggestion or change that we don't feel we should currently apply for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 18, 2024
@christophstrobl
Copy link
Member

Thanks for getting in touch. We prefer to use GitHub issues only for bugs and enhancements. The question on SO seems to have been answered already.

@christophstrobl christophstrobl closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
@ere-one
Copy link
Author

ere-one commented Apr 18, 2024

Actually it is a bug in the Sppring Data JPA Repository. Because entityManager.flush() must be called implicitally by a vendor if FlushModeType.AUTO is used, see related JEE API Doc:
https://docs.oracle.com/javaee%2F7%2Fapi%2F%2F/javax/persistence/FlushModeType.html

"... the persistence provider is responsible for ensuring that all updates to the state of all entities in the persistence context which could potentially affect the result of the query are visible to the processing of the query. ..."

In case of a Spring-Data JPA Repository methods annotated with @query, the entityManager.flush() will be called implicitally before executing the query, so the query can use/see the changes made in the same transaction.
In case of a Spring-Data JPA Repository methods annotated with @procedure the entityManager.flush() will not be called implicitally, so the stored procedure, in which queries may be used, will not use/see changes made in the same transaction.

We use Spring-Boot 2.7.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants