-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Add option to allow Spring Batch custom isolation levels with JPA #28802
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
Thanks for the suggestion, paging @benas. |
Thank you for this suggestion. What is the expected way to provide a custom isolation level when My thinking is that if the goal is to avoid extending a class to override a property, why not make the isolation level configurable with a property like other Batch properties (table-prefix, schema, etc)? What do you think? |
Good point, thank you! Let's say we have a
What do you think? |
@benas Could Batch provide a more strongly typed method for configuring the isolation level using Framework's |
@tiborsulyan Thank you for your feedback. This seems reasonable to me. @wilkinsona Yes, I created spring-projects/spring-batch#4032 for that. |
We had some discussion with my colleagues and have another proposal. What about changing the default behaviour to allow Spring Batch to use custom isolation levels by default? I was thinking about the following logic (in JpaBatchConfigurer)
What do you think? |
Thanks for the suggestion, @tiborsulyan, but I don't think we would want to introduce that level of coupling between |
Closing in favor of #28859 |
Uh oh!
There was an error while loading. Please reload this page.
Currently Spring Boot overrides Spring Batch default behaviour and specifies the connection-default isolation level for creating job metadata in the database (Spring Batch default is SERIALIZABLE with an option to override it).
This can cause issues where concurrent job executions can occur on the same database (our case).
So far the recommended way to workaround this was to override BasicBatchConfigurer (Spring Boot 1.x) or JpaBatchConfigurer (Spring Boot 2.x) and modify this method:
I propose to have a configuration property instead which can be used to disable this behaviour and allow Spring Batch to use custom isolation levels. For example,
spring.batch.jpa.allow-custom-isolation-levels
withfalse
as default value which means keep the current behaviour.Rationale:
This behaviour was introduced in 2014 by this commit. Since then Spring Boot adopted HikariCP as default connection pool, which enables safe usage of custom isolation levels on top of JPA, because connections returned to HikariCP are properly cleaned up. Also, most JPA vendors allow this nowadays (see various JpaDialect implementations), however, not in all cases.
Since the connection pool can be changed to a less well-behaving one, also, not all JPA vendors support this, the default setting for the new property would be
false
. This would also ensure backwards compatibility.Happy to contribute a PR for this enhancement request.
The text was updated successfully, but these errors were encountered: