问题描述
- myBatis中的莫名其妙的java.lang.NullPointerException,求指教
-
xml:<!-- ognl访问静态方法的表达式 为@class@method(args),以下为调用Ognl.isNotEmpty()方法,还有其它方法如isNotBlank()可以使用,具体请查看Ognl类 -->
AND SRLNO = '${h_srlno}'
AND URGEDATE = '${h_date}'
</where> </sql> <select id="findBySrlnoDate" parameterType="java.util.HashMap" resultType="com.mf.cntrtmng.entity.BsnsOverdueUrge"> SELECT <include refid="selectId" /> FROM bsns_overdue_urge <include refid="querywheresrlnodate"/> </select>
DAO:
public BsnsOverdueUrge findBySrlnoDate(Map params) throws DataAccessException;Serviceimpl:
public boolean exist(Map params) {
System.out.println("=====搜索出来的");
System.out.println(params);
if(bsnsOverdueUrgeDao.findBySrlnoDate(params)==null)
return true;
else
return false;
}错误日志:
=====搜索出来的
{h_srlno=JH201505281535107052, h_date=20150601}
2015-06-01 15:19:42,922 DEBUG http-bio-8080-exec-3 - Creating a new SqlSession
2015-06-01 15:19:42,922 DEBUG http-bio-8080-exec-3 - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d41567b]
2015-06-01 15:19:42,924 DEBUG http-bio-8080-exec-3 - JDBC Connection [jdbc:mysql://localhost:3306/microfinance?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true, UserName=root@localhost, MySQL-AB JDBC Driver] will be managed by Spring
2015-06-01 15:19:42,925 DEBUG http-bio-8080-exec-3 - ooo Using Connection [jdbc:mysql://localhost:3306/microfinance?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true, UserName=root@localhost, MySQL-AB JDBC Driver]
2015-06-01 15:19:42,928 DEBUG http-bio-8080-exec-3 - ==> Preparing: select count(1) from (SELECT NO, SRLNO, CLNTNO, URGEID, URGENAME, URGEDATE FROM bsns_overdue_urge WHERE SRLNO = 'JH201505281535107052' AND URGEDATE = '20150601') tmp_count
2015-06-01 15:19:42,929 DEBUG http-bio-8080-exec-3 - ==> Parameters:
2015-06-01 15:19:42,930 DEBUG http-bio-8080-exec-3 - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d41567b]
2015-06-01 15:19:42,930 DEBUG http-bio-8080-exec-3 - Initiating transaction rollback
2015-06-01 15:19:42,931 DEBUG http-bio-8080-exec-3 - Rolling back JDBC transaction on Connection [jdbc:mysql://localhost:3306/microfinance?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true, UserName=root@localhost, MySQL-AB JDBC Driver]
2015-06-01 15:19:42,932 DEBUG http-bio-8080-exec-3 - Transaction synchronization rolling back SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d41567b]
2015-06-01 15:19:42,932 DEBUG http-bio-8080-exec-3 - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d41567b]
2015-06-01 15:19:42,933 DEBUG http-bio-8080-exec-3 - Releasing JDBC Connection [jdbc:mysql://localhost:3306/microfinance?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true, UserName=root@localhost, MySQL-AB JDBC Driver] after transaction
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:Error querying database. Cause: java.lang.NullPointerException
The error may exist in file [E:SpringSource.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebappsmicrofinance20150203WEB-INFclassescommfcntrtmngentitymapperbsnsoverdueurge-mapper.xml]
The error may involve com.mf.cntrtmng.dao.BsnsOverdueUrgeDao.findBySrlnoDate-Inline
The error occurred while setting parameters
Cause: java.lang.NullPointerException
2015-06-01 15:19:42,933 DEBUG http-bio-8080-exec-3 - Returning JDBC Connection to DataSource
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
at com.sun.proxy.$Proxy11.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at com.sun.proxy.$Proxy114.findBySrlnoDate(Unknown Source)
at com.mf.cntrtmng.service.impl.BsnsOverdueUrgeServiceImpl.exist(BsnsOverdueUrgeServiceImpl.java:128)
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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy115.exist(Unknown Source)
at com.mf.aftrmng.controller.LoanWarnController.showUrgeInfo(LoanWarnController.java:310)
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.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.mf.interceptor.HeadInterceptor.doFilter(HeadInterceptor.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)从日志里面打印的SQL,可以在数据库中搜索,怎么返回值变成了count(),我不是在xml中配置的返回值类型为一个对象类型么“resultType="com.mf.cntrtmng.entity.BsnsOverdueUrge"?”然后包了莫名其妙的空指针错误,求大神帮忙看看,小弟感激不尽~~
解决方案
FROM bsns_overdue_urge
这两个引用的sql也贴下
解决方案二:
sql里的字段与实体类里要对应,大小写也要注意