程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> mybaits非配置原因,導致SqlSession was not registered for synchronization異常,mybaitssqlsession

mybaits非配置原因,導致SqlSession was not registered for synchronization異常,mybaitssqlsession

編輯:更多數據庫知識

mybaits非配置原因,導致SqlSession was not registered for synchronization異常,mybaitssqlsession


今天運行程序時報了

SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@69d4fb43] was not registered for synchronization because synchronization is not active

[11:03:17]-Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@69d4fb43]

由於異常是集中處理的,所以報了這樣的錯誤,查了半天,網上結果都是說配置文件出錯的,可是我的項目配置文件肯定是沒錯的,因為項目都開發了好長時間了,只是我今天寫了個方法才報的這個錯誤,所以排除配置文件出錯,可是我寫的方法應該沒問題的,以前也這樣寫的呀。

      網上查半天沒找到原因,沒辦法,只能看看自己的程序了,把自己寫的方法異常直接打印出來,先不集中處理,然後異常出來了:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘departid‘ in ‘class java.lang.String‘

 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)

 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)

 at com.sun.proxy.$Proxy15.selectOne(Unknown Source)

 at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)

 at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)

 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)

 at com.sun.proxy.$Proxy125.selectCount(Unknown Source)

 at com.sinog2c.service.impl.yzgl.TbyzScoreServiceImpl.selectCount(TbyzScoreServiceImpl.java:66)

 at com.sinog2c.mvc.controller.yzgl.criminalexam.JifenController.getLastMonthScoreList(JifenController.java:76)

 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.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)

 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)

 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)

 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)

 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)

 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)

 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)

 at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)

 at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

 at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)

 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)

 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

 at java.lang.Thread.run(Thread.java:662)

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘departid‘ in ‘class java.lang.String‘

 at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:380)

 at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:170)

 at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:152)

 at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:48)

 at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)

 at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextMap.get(DynamicContext.java:97)

 at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:116)

 at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)

 at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92)

 at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)

 at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)

 at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:49)

 at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)

 at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)

 at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:56)

 at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)

 at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)

 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)

 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413)

 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395)

 at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:48)

 at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)

 at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:33)

 at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)

 at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:40)

 at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:278)

 at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:75)

 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)

 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)

 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)

 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.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)

 ... 40 more

根據這個異常再查程序,發現問題出現在departid這個參數,再查源程序,發現原來我寫的那個方法的sql在mapper.xml文件裡引用了對參數departid進行判斷是否為null或空,所以才報 There is no getter for property named ‘departid‘ in ‘class java.lang.String‘異常。

解決方法:一、在方法傳參時,加param參數標識,如:countNum(@Param("departid")String departid);

                  二、在方法傳參時,把參數換成map或對象。

希望通過此文能解決這類問題,謝謝大家對本站的支持!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved