-
Notifications
You must be signed in to change notification settings - Fork 1.5k
add flushAutomatically attribute to @Modifying annotation [DATAJPA-806] #1167
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
Comments
Oliver Drotbohm commented Shouldn't the execution of a query flush the |
Ciri commented JPA’s AUTO FlushModeType and Hibernate: if the current executed query is not going to hit the pending SQL INSERT/UPDATE/DELETE statements then the flush is not strictly required. As stated in the reference documentation, the AUTO flush strategy may sometimes synchronize the current persistence context prior to a query execution. The clearAutomatically property drops all the pending changes in the EntityManager that are not related to the current update query (cause they are not automatically flushed). That's why I'm asking for a new property to force the EntityManager to flush changes |
Ciri commented Spring Data JPA - Reference Documentationhttp://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.modifying-queries
Hibernate implementationWhen an org.hibernate.event.internal.DefaultAutoFlushEventListenerprivate boolean flushIsReallyNeeded(AutoFlushEvent event, final EventSource source) {
return source.getActionQueue()
.areTablesToBeUpdated( event.getQuerySpaces() ) ||
source.getFlushMode()==FlushMode.ALWAYS;
} If other tables have pending changes, the flush is not done before the execution of the query and the clear of the flushAutomatically attribute in
|
Łukasz Glapiński commented Any updates on this one? |
Ciri commented remote development branch https://github.com/ciri-cuervo/spring-data-jpa/tree/issue/DATAJPA-806 |
Florian Hopf commented I can confirm that the workaround with the custom repository solves this issue but is cumbersome. Are there any plans to incorporate the proposed PR? The current behaviour can be quite surprising to the user |
Oliver Drotbohm commented The PR looks like a decent start and we could go ahead with it. I'd propose the following changes to it:
|
Ciri opened DATAJPA-806 and commented
@Modifying
annotation has clearAutomatically attribute which defines whether it should clear the underlying persistence context after executing the modifying query.Code example:
When executing modifying queries with this attribute activated, it drops all non-flushed changes still pending in the EntityManager.
To avoid this situation I had to implement a custom repository to manually execute the flush of the EntityManager, then the update query, and finally clear the underlying persistence context:
Is it possible to add a new attribute to
@Modifying
annotation called flushAutomatically to automatically flush all non-persisted changes to the underlying context before executing the modifying query?Affects: 1.9 GA (Gosling)
Reference URL: http://stackoverflow.com/questions/32258857/spring-boot-data-jpa-modifying-update-query-refresh-persistence-context
Backported to: 2.0.4 (Kay SR4), 1.11.11 (Ingalls SR11)
6 votes, 8 watchers
The text was updated successfully, but these errors were encountered: