Mybatis执行报错 Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [java.lang.NullPointerException]
真得吐槽一下,mybatis就不能把这个错报成 column 'xxx' is not exist 吗。发现了Mybatis一个很不直观的错误,从字面上根本看不出哪里有问题。可以看到这是一个虚拟字段,并不存在于表中,用它来做条件肯定有问题。只能看出是空指针,于是我用断点跟踪我传的条件,发现全部都有值。于是把这个条件去掉之后,顺利解决问题。请看看我的查询条件怎么写的。
·
发现了Mybatis一个很不直观的错误,从字面上根本看不出哪里有问题

异常详情:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [java.lang.NullPointerException]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy180.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:173)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:78)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
只能看出是空指针,于是我用断点跟踪我传的查询条件,发现全部都有值。
结果万万没想到是字段不存在导致的...........
请看我的查询条件怎么写的

这个字段点进去

注意!!!问题来了 !!!
可以看到这是一个虚拟字段,并不存在于表中,用它来做条件肯定有问题。
于是把这个条件去掉之后,顺利解决问题。
真得吐槽一下,mybatis就不能把这个错报成 column 'xxx' is not exist 吗。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)