MyBatis Cause: java.lang.NullPointerException出现异常问题解决方案分享

1 篇文章 0 订阅
1 篇文章 0 订阅

报错日志如下:(请详细查看加粗部分)

2019-06-13 11:08:00.322 -ERROR 7068 [nio-8082-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is 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 [D:\ide_project\yunzhi\evaluate-project\evaluate-project-dao\target\classes\mapper\uc\UcRefContactMapper.xml]
### The error may involve com.yunzhi.evaluate.mapper.uc.UcRefContactMapper.selectPageByCustomerId
### The error occurred while handling results(错误类别说明是结果集绑定出现异常)
### SQL: SELECT t1.fd_id, t1.fd_targetId,                t2.fd_id cid, t2.fd_cellphone, t2.fd_headImg, t2.fd_name,                t2.fd_level,  t2.fd_realName, t2.fd_roleType, t2.fd_introduce         FROM uc_ref_contact t1 LEFT JOIN uc_customer t2         ON t2.fd_id = t1.fd_targetId          WHERE  t1.fd_customerId= ?                                           and t2.fd_roleType = ?          order by t1.fd_lastChatDate desc LIMIT ?
### Cause: java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
   at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
   at org.apache.ibatis.reflection.DefaultReflectorFactory.findForClass(DefaultReflectorFactory.java:42)
   at org.apache.ibatis.reflection.MetaClass.<init>(MetaClass.java:39)
   at org.apache.ibatis.reflection.MetaClass.forClass(MetaClass.java:43)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:612)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:594)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:909)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:963)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:918)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:881)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:328)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:303)
   at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:196)
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
   at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
   at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326)
   at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
   at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
   at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:136)
   at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
   at com.sun.proxy.$Proxy248.query(Unknown Source)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
   at sun.reflect.GeneratedMethodAccessor763.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
   at com.sun.proxy.$Proxy112.selectList(Unknown Source)
   at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
   at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:139)
   at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:76)
   at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
   at com.sun.proxy.$Proxy186.selectPageByCustomerId(Unknown Source)
   at com.yunzhi.evaluate.service.uc.impl.UcRefContactServiceImpl.getPage(UcRefContactServiceImpl.java:59)
   at com.yunzhi.evaluate.service.uc.impl.UcRefContactServiceImpl$$FastClassBySpringCGLIB$$bb1d2916.invoke(<generated>)
   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
对应的Mapper.xml内容如下:

<resultMap type="com.yunzhi.evaluate.vo.uc.UcRefContactVO" id="joinMap">
    <id column="fd_id" property="id"/>
    <result column="fd_targetId" property="targetId"/>
    <association property="customerVO">
        <id column="cid" property="id"/>
        <result column="fd_cellphone" property="cellphone"/>
        <result column="fd_headImg" property="headImg"/>
        <result column="fd_name" property="name"/>
        <result column="fd_realName" property="realName"/>
        <result column="fd_level" property="level"/>
        <result column="fd_roleType" property="roleType"/>
        <result column="fd_introduce" property="introduce"/>
    </association>
    
</resultMap>
<select id="selectPageByCustomerId" parameterType="java.util.Map"  resultMap="joinMap">
    SELECT t1.fd_id, t1.fd_targetId,
           t2.fd_id cid, t2.fd_cellphone, t2.fd_headImg, t2.fd_name,
           t2.fd_level,  t2.fd_realName, t2.fd_roleType, t2.fd_introduce
    FROM uc_ref_contact t1 LEFT JOIN uc_customer t2 ON t2.fd_id = t1.fd_targetId
    <where>
        <if test="customerId != null">
            and t1.fd_customerId= #{customerId}
        </if>
        <if test="type != null">
            and t2.fd_roleType = #{type}
        </if>
    </where>
    order by t1.fd_lastChatDate desc
</select>

问题 :association 没有指定Java对象的类型,修改过后为:

<resultMap type="com.yunzhi.evaluate.vo.uc.UcRefContactVO" id="joinMap">
    <id column="fd_id" property="id"/>
    <result column="fd_targetId" property="targetId"/>
    <association property="customerVO" javaType="com.yunzhi.evaluate.vo.uc.UcCustomerVO">
        <id column="cid" property="id"/>
        <result column="fd_cellphone" property="cellphone"/>
        <result column="fd_headImg" property="headImg"/>
        <result column="fd_name" property="name"/>
        <result column="fd_realName" property="realName"/>
        <result column="fd_level" property="level"/>
        <result column="fd_roleType" property="roleType"/>
        <result column="fd_introduce" property="introduce"/>
    </association>
   
</resultMap>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值