Skip to content

Add option to allow Spring Batch custom isolation levels with JPA #28802

Closed
@tiborsulyan

Description

@tiborsulyan

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:

	@Override
	protected String determineIsolationLevel() {
		logger.warn("JPA does not support custom isolation levels, so locks may not be taken when launching Jobs");
		return "ISOLATION_DEFAULT";
	}

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 with false 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions