【有关问题】Invoking destroy method 'close' on bean with name 'sqlSession'
【问题】Invoking destroy method 'close' on bean with name 'sqlSession'
spring 3.2.3 + mybatis 3.2.2,在用junit4做单元测试时,报如下错误:
spring在试图关闭session时,发现sqlsession不允许关闭。
网上查找说:
MyBatis3.1.1 :public abstract interface SqlSession extends Closeable
MyBatis3.2.0 :public abstract interface SqlSession.
------------------------------------
最终原因是代码有一个实体报空了,代码如下:
c_summary 为null时,报以上错。
spring 3.2.3 + mybatis 3.2.2,在用junit4做单元测试时,报如下错误:
[DEBUG] 2014-02-02 23:08:59 :Invoking destroy method 'close' on bean with name 'sqlSession' [WARN ] 2014-02-02 23:08:59 :Invocation of destroy method 'close' failed on bean with name 'sqlSession' java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession at org.mybatis.spring.SqlSessionTemplate.close(SqlSessionTemplate.java:306) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:327)
spring在试图关闭session时,发现sqlsession不允许关闭。
网上查找说:
MyBatis3.1.1 :public abstract interface SqlSession extends Closeable
MyBatis3.2.0 :public abstract interface SqlSession.
------------------------------------
最终原因是代码有一个实体报空了,代码如下:
//当月预算实际消费 Summary c_summary = this.summaryService.findByTypeAndTrdate("totalout", lasttrdate, user.getId()); if(!c_summary.getValue().equals(orderr.getValue())){ commit.append(" 其它未预算项:" + DataUtil.sub(c_summary.getValue(), orderr.getValue())); }
c_summary 为null时,报以上错。