Bug description
When launching an Spring Batch Job with jobLauncher.run(job, parameters), the Job is being unable to run since an exception is being thrown: org.springframework.dao.DataAccessResourceFailureException: Hibernate transaction: Unable to commit against JDBC Connection; This connection has been closed.
org.springframework.dao.DataAccessResourceFailureException: Hibernate transaction: Unable to commit against JDBC Connection; This connection has been closed.
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:132)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:107)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:116)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:269)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:256)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:241)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:567)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:795)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:758)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:698)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:416)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
at jdk.proxy3/jdk.proxy3.$Proxy301.getLastJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.TaskExecutorJobLauncher.run(TaskExecutorJobLauncher.java:109)`
...
Caused by: org.postgresql.util.PSQLException: This connection has been closed.
at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:1012)
at org.postgresql.jdbc.PgConnection.commit(PgConnection.java:998)
at io.zonky.test.db.provider.support.BlockingDatabaseWrapper$BlockingConnectionWrapper.commit(BlockingDatabaseWrapper.java:165)
at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.commit(AbstractLogicalConnectionImplementor.java:87)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:268)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:563)
... 217 common frames omitted
Environment
implementation 'org.springframework.batch:spring-batch-core:5.2.3'
Java 21
Spring Boot 3.5.6
Database: Zonky Postgres
implementation 'org.postgresql:postgresql:42.7.7'
testImplementation 'io.zonky.test:embedded-database-spring-test:2.6.0'
testImplementation 'io.zonky.test:embedded-postgres:2.1.0'
testRuntimeOnly 'io.zonky.test.postgres:embedded-postgres-binaries-darwin-amd64:17.2.0'
Steps to reproduce
Zonky Postgres + jobLauncher.run(job, parameters) + 'org.springframework.batch:spring-batch-core:5.2.3'
Expected behavior
The Job to be launched without throwing exceptions.
Conclusions after investigation
Version spring-batch-core:5.2.3
v5.2.2...v5.2.3#diff-9c5fb3d1b7e3b0f54bc5c4182965c4fe1f9023d449017cece3005d3f90e8e4d8
In 5.2.3 version, JdbcTemplate::queryForStream is being used in a try-with-resources block, which causes the Database Connection being closed after the stream has been consumed, which cause consecutive requests to JdbcJobInstanceDao::getJobInstance throw
org.springframework.dao.DataAccessResourceFailureException: Hibernate transaction: Unable to commit against JDBC Connection; This connection has been closed.
org.springframework.dao.DataAccessResourceFailureException: Hibernate transaction: Unable to commit against JDBC Connection; This connection has been closed.
since the connection was already closed by the first request.

Bug description
When launching an Spring Batch Job with jobLauncher.run(job, parameters), the Job is being unable to run since an exception is being thrown: org.springframework.dao.DataAccessResourceFailureException: Hibernate transaction: Unable to commit against JDBC Connection; This connection has been closed.
Environment
implementation 'org.springframework.batch:spring-batch-core:5.2.3'
Java 21
Spring Boot 3.5.6
Database: Zonky Postgres
implementation 'org.postgresql:postgresql:42.7.7'
testImplementation 'io.zonky.test:embedded-database-spring-test:2.6.0'
testImplementation 'io.zonky.test:embedded-postgres:2.1.0'
testRuntimeOnly 'io.zonky.test.postgres:embedded-postgres-binaries-darwin-amd64:17.2.0'
Steps to reproduce
Zonky Postgres + jobLauncher.run(job, parameters) + 'org.springframework.batch:spring-batch-core:5.2.3'
Expected behavior
The Job to be launched without throwing exceptions.
Conclusions after investigation
Version spring-batch-core:5.2.3
v5.2.2...v5.2.3#diff-9c5fb3d1b7e3b0f54bc5c4182965c4fe1f9023d449017cece3005d3f90e8e4d8
In 5.2.3 version, JdbcTemplate::queryForStream is being used in a try-with-resources block, which causes the Database Connection being closed after the stream has been consumed, which cause consecutive requests to JdbcJobInstanceDao::getJobInstance throw
since the connection was already closed by the first request.