Bug: Hibernate fails with "Operation not allowed after ResultSet closed" when using ShardingSphere JDBC
Description
The application fails when executing a Spring Data JPA repository query. Hibernate throws a JpaSystemException while extracting data from the JDBC ResultSet.
The failing repository method:
Error:
org.springframework.orm.jpa.JpaSystemException:
Could not extract column [1] from JDBC ResultSet
[Operation not allowed after ResultSet closed]
Root cause:
java.sql.SQLException: Operation not allowed after ResultSet closed
Environment
- Spring Framework: 7.0.8
- Spring Data JPA: 4.0.6
- Hibernate ORM: 7.2.19.Final
- MySQL Connector/J: 9.7.0
- HikariCP: 7.0.2
- ShardingSphere JDBC: 5.5.3
- Database: MySQL
- Java: 21
Stack Trace
Caused by: java.sql.SQLException:
Operation not allowed after ResultSet closed
at com.mysql.cj.jdbc.result.ResultSetImpl.checkClosed(ResultSetImpl.java:494)
at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1280)
at com.mysql.cj.jdbc.result.ResultSetImpl.getLong(ResultSetImpl.java:882)
at com.zaxxer.hikari.pool.HikariProxyResultSet.getLong(HikariProxyResultSet.java:...)
at org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult.getValue(JDBCStreamQueryResult.java:82)
at org.apache.shardingsphere.infra.merge.result.impl.stream.StreamMergedResult.getValue(StreamMergedResult.java:47)
at org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSet.getLong(ShardingSphereResultSet.java:134)
at org.hibernate.type.descriptor.jdbc.BigIntJdbcType$2.doExtract(BigIntJdbcType.java:76)
Steps to Reproduce
-
Configure a Spring Boot application with:
- Spring Data JPA
- Hibernate 7.2.x
- ShardingSphere JDBC 5.5.3
- MySQL Connector/J 9.7.0
-
Execute a repository query:
List<Entity> findByAssignedUserId(Long assignedUserId);
- Hibernate fails while hydrating the entity result.
Expected Behavior
Hibernate should successfully read all columns from the JDBC ResultSet.
The ResultSet should remain open until Hibernate completes processing the query result.
Actual Behavior
The JDBC ResultSet is closed before Hibernate finishes reading data:
ResultSet closed
↓
Hibernate tries to extract column value
↓
SQLException:
Operation not allowed after ResultSet closed
Analysis
The failure appears to occur inside ShardingSphere JDBC streaming result handling:
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult
Possible compatibility issue between:
- Hibernate 7.2.x result processing
- ShardingSphere JDBC streaming merge implementation
- MySQL Connector/J 9.7 ResultSet lifecycle handling
Additional Information
The exception happens during Hibernate entity loading:
EntitySelectFetchInitializer.resolveInstance
The application does not manually close the ResultSet.
Request
Please investigate whether ShardingSphere JDBC 5.5.3 is fully compatible with Hibernate 7.2.x.
The ResultSet lifecycle should be reviewed to ensure the underlying JDBC ResultSet is not closed before Hibernate completes entity hydration.
Bug: Hibernate fails with "Operation not allowed after ResultSet closed" when using ShardingSphere JDBC
Description
The application fails when executing a Spring Data JPA repository query. Hibernate throws a
JpaSystemExceptionwhile extracting data from the JDBCResultSet.The failing repository method:
findByAssignedUserIdError:
Root cause:
Environment
Stack Trace
Steps to Reproduce
Configure a Spring Boot application with:
Execute a repository query:
Expected Behavior
Hibernate should successfully read all columns from the JDBC
ResultSet.The
ResultSetshould remain open until Hibernate completes processing the query result.Actual Behavior
The JDBC
ResultSetis closed before Hibernate finishes reading data:Analysis
The failure appears to occur inside ShardingSphere JDBC streaming result handling:
Possible compatibility issue between:
Additional Information
The exception happens during Hibernate entity loading:
The application does not manually close the
ResultSet.Request
Please investigate whether ShardingSphere JDBC 5.5.3 is fully compatible with Hibernate 7.2.x.
The ResultSet lifecycle should be reviewed to ensure the underlying JDBC ResultSet is not closed before Hibernate completes entity hydration.