AHUTwzw opened a new issue, #35600:
URL: https://github.com/apache/shardingsphere/issues/35600

   ### Issue Context:
   1.Due to legacy design constraints, the system employs a dual-primary key 
approach combining MySQL auto-increment keys and business keys.
   2.Currently, only sharded tables utilize ShardingJDBC, while other tables 
retain their original logic.
   
   Observed Problem:‌
   When executing multiple saveBatch() operations using MyBatis-Plus:
   The first batch insertion succeeds
   Subsequent operations throw a ResultSet is closed exception
   This issue occurs specifically in scenarios using MySQL's auto-increment 
primary keys
   
   ```
   @Service
       public class ServiceA {
           public void functionA() {
               for(...) {
                   List<POJOA> pojoaList = xxx;
                   serviceB.saveBatch(pojoaList);
               }
           }
       }
       
       public interface IServiceB() extends BaseService<POJOA> {
       }
   
       @Service
       public class ServiceB extends BaseServiceImpl<POJOAMapper, POJOA> 
implements IServiceB {
       }
   ```
   I found that in the `ShardingSpherePreparedStatement` class, the 
`executeBatch` method reuses the `currentBatchGeneratedKeysResultSet`. However, 
in the `finally` block, when the `clearBatch` method is executed, the 
`currentBatchGeneratedKeysResultSet` object is not set to `null`. This causes 
an issue when the second `executeBatch` operation comes in and retrieves the 
`currentBatchGeneratedKeysResultSet` object, which has its `isClosed` attribute 
set to `true`, resulting in an error. I resolved my problem by setting it to 
`null` in the `finally` block.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
notifications-unsubscr...@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to