mybatis / mybatis-3

MyBatis SQL mapper framework for Java
http://mybatis.github.io/mybatis-3/
Apache License 2.0
19.79k stars 12.86k forks source link

useing ResultHandler result of sqlexception when query huge data #716

Closed feihu618 closed 8 years ago

feihu618 commented 8 years ago

MyBatis version

3.3.1

Database vendor and version

mysql5.7

Test case or example project

    <select id="getAllBlocker" fetchSize="2000" resultMap="BlockerListSyncRedisMap">
        select
        <include refid="blockerListSyncRedisColumns" />
        from blocker a
        left join punish_action punish on a.punish_name = punish.name
    </select>
public interface BlockerMapper{
      public void getAllBlocker(ResultHandler handler);
}

blockerMapper.getAllBlocker((ResultContext resultContext) -> {

                    doRefresh(()->handle((Blocker) resultContext.getResultObject(), INSERT_DB), resultContext.getResultCount(), blackAccount);

                });

Steps to reproduce

Expected result

query all reocords in db

Actual result

DefaultTestContext@5c18298f testClass = RedisCacheServiceTest, testInstance = com.pajk.risk.web.test.service.RedisCacheServiceTest@31f924f5, testMethod = refreshTest@RedisCacheServiceTest, testException = org.springframework.dao.TransientDataAccessResourceException: 
### Error querying database.  Cause: java.sql.SQLException: Operation not allowed after ResultSet closed
### The error may exist in file [/home/ginkgo/IdeaProjects/jk/risk-web/target/classes/META-INF/mybatis/sqlmap/BlockerMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select                   a.id as a_id,value,source,invalidate_time,domain_id,start_time,         punish.key,punish.name as p_name               from blocker a         left join punish_action punish on a.punish_name = punish.name
### Cause: java.sql.SQLException: Operation not allowed after ResultSet closed
; SQL []; Operation not allowed after ResultSet closed; nested exception is java.sql.SQLException: Operation not allowed after ResultSet closed, mergedContextConfiguration = [MergedContextConfiguration@5579bb86 testClass = RedisCacheServiceTest, locations = '{}', classes = '{class com.pajk.risk.web.RiskDBConfig, class com.pajk.risk.web.RefServiceConfig, class com.pajk.risk.web.RedisConfig, class com.pajk.risk.web.WebConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]], class dirties context [false], class mode [null], method dirties context [false].
2016-06-23 20:22:50.355 DEBUG 13247 --- [pool-6-thread-3] com.pajk.pash.pio.Reader                 : /home/admin/pash/hugo_agent/pash-pio/pi-com.pajk.risk.web.core.pash.Joblistener#risk-web_test not exists, wait for agent creating it!

org.springframework.dao.TransientDataAccessResourceException: 
### Error querying database.  Cause: java.sql.SQLException: Operation not allowed after ResultSet closed
### The error may exist in file [/home/ginkgo/IdeaProjects/jk/risk-web/target/classes/META-INF/mybatis/sqlmap/BlockerMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select                   a.id as a_id,value,source,invalidate_time,domain_id,start_time,         punish.key,punish.name as p_name               from blocker a         left join punish_action punish on a.punish_name = punish.name
### Cause: java.sql.SQLException: Operation not allowed after ResultSet closed
; SQL []; Operation not allowed after ResultSet closed; nested exception is java.sql.SQLException: Operation not allowed after ResultSet closed

    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:106)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
    at com.sun.proxy.$Proxy40.select(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.select(SqlSessionTemplate.java:219)
    at org.apache.ibatis.binding.MapperMethod.executeWithResultHandler(MapperMethod.java:108)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:60)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    at com.sun.proxy.$Proxy49.getAllBlack(Unknown Source)
    at com.pajk.risk.web.core.service.RedisCacheService.refresh(RedisCacheService.java:99)
    at com.pajk.risk.web.test.service.RedisCacheServiceTest.refreshTest(RedisCacheServiceTest.java:90)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
    at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:804)
    at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6986)
    at com.alibaba.druid.filter.FilterChainImpl.resultSet_next(FilterChainImpl.java:654)
    at com.alibaba.druid.filter.FilterAdapter.resultSet_next(FilterAdapter.java:1885)
    at com.alibaba.druid.filter.FilterChainImpl.resultSet_next(FilterChainImpl.java:651)
    at com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl.next(ResultSetProxyImpl.java:882)
    at com.alibaba.druid.pool.DruidPooledResultSet.next(DruidPooledResultSet.java:69)
    at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:67)
    at com.sun.proxy.$Proxy65.next(Unknown Source)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.shouldProcessMoreRows(DefaultResultSetHandler.java:310)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:702)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:264)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:239)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.select(DefaultSqlSession.java:128)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.select(DefaultSqlSession.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
    ... 40 more
harawata commented 8 years ago

I tried, but couldn't reproduce the exception. Please create a test case or an example project so that we can reproduce the problem.

harawata commented 8 years ago

No reply.

JKTerrific commented 6 years ago

Perhaps, i have reproduced the exception with spring timed task .I try to set same schedule to run different jobs and the exception occurs in the first time the jobs running.

image


        at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:194)
        at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
        at com.sun.proxy.$Proxy93.getUnassignedWO(Unknown Source)
        at com.ydl.wo.service.biz.impl.WoWorkOrderBizImpl.getUnassignedWO(WoWorkOrderBizImpl.java:91)
        at com.ydl.wo.service.WorkOrderScheduler.distWorkOrder(WorkOrderScheduler.java:43)
        at com.ydl.wo.service.WorkOrderScheduler$$FastClassBySpringCGLIB$$c54717b3.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
        at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
        at org.springframework.cloud.sleuth.instrument.scheduling.TraceSchedulingAspect.traceBackgroundThread(TraceSchedulingAspect.java:71)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
        at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
        at com.ydl.wo.service.WorkOrderScheduler$$EnhancerBySpringCGLIB$$d37d5821.distWorkOrder(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
        at java.util.concurrent.FutureTask.run(FutureTask.java)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.NullPointerException
### Cause: java.lang.NullPointerException
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:354)
        ... 41 common frames omitted
Caused by: java.lang.NullPointerException: null
        at com.github.pagehelper.util.SqlUtil.doIntercept(SqlUtil.java:120)
        at com.github.pagehelper.util.SqlUtil.intercept(SqlUtil.java:84)
        at com.github.pagehelper.PageHelper.intercept(PageHelper.java:50)
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
        at com.sun.proxy.$Proxy122.query(Unknown Source)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
        ... 47 common frames omitted```
JKTerrific commented 6 years ago

with mybatis 3.3.0