今天写代码的时候遇到一个非常傻的错误,代码目的:是在一个表里,通过subject_id来分类查找学科详情,正确返回如下:
表结构如下:
原因如下
问题:
第一应该返回次数是2,
但是只执行了一次subject_id=3,并且报了一个null空异常,非常的奇怪
错误log:
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.UnsupportedOperationException
### The error may exist in file [F:\Huaicai-GXDZ\hucais-customized-channe\target\classes\mapper\KnowledgeCategoryMapper.xml]
### The error may involve com.hucais.infra.mapper.KnowledgeCategoryMapper.selectName
### The error occurred while handling results
### SQL: select category_name from customized_knowledge_category where subject_id = ?
### Cause: java.lang.UnsupportedOperationException
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.6.jar:3.5.6]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ~[mybatis-spring-2.0.6.jar:2.0.6]
... 155 common frames omitted
Caused by: java.lang.UnsupportedOperationException: null
at org.apache.ibatis.reflection.wrapper.CollectionWrapper.findProperty(CollectionWrapper.java:48) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.reflection.MetaObject.findProperty(MetaObject.java:85) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createAutomaticMappings(DefaultResultSetHandler.java:549) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyAutomaticMappings(DefaultResultSetHandler.java:573) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:392) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:344) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:318) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:291) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:184) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.loader.ResultLoader.selectList(ResultLoader.java:81) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.loader.ResultLoader.loadResult(ResultLoader.java:70) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getNestedQueryMappingValue(DefaultResultSetHandler.java:816) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getPropertyMappingValue(DefaultResultSetHandler.java:521) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:497) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:394) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:344) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:318) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:291) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:184) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:3.5.6]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.5.6.jar:3.5.6]
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) ~[mybatis-3.5.6.jar:3.5.6]
at org.hzero.boot.platform.data.permission.handler.DataCacheResultHandler.intercept(DataCacheResultHandler.java:79) ~[hzero-boot-platform-1.11.1.RELEASE.jar:1.11.1.RELEASE]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
at com.sun.proxy.$Proxy465.query(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) ~[mybatis-3.5.6.jar:3.5.6]
at com.sun.proxy.$Proxy465.query(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) ~[mybatis-3.5.6.jar:3.5.6]
at org.hzero.mybatis.parser.SqlParserInterceptor.intercept(SqlParserInterceptor.java:117) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:1.11.1.RELEASE]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
at com.sun.proxy.$Proxy465.query(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) ~[mybatis-3.5.6.jar:3.5.6]
at org.hzero.mybatis.security.DataSecurityInterceptor.intercept(DataSecurityInterceptor.java:87) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:1.11.1.RELEASE]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
at com.sun.proxy.$Proxy465.query(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) ~[mybatis-3.5.6.jar:3.5.6]
at org.hzero.mybatis.security.SecurityTokenInterceptor.intercept(SecurityTokenInterceptor.java:36) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:1.11.1.RELEASE]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
at com.sun.proxy.$Proxy465.query(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) ~[mybatis-3.5.6.jar:3.5.6]
at org.hzero.mybatis.security.CrossSchemaInterceptor.intercept(CrossSchemaInterceptor.java:74) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:1.11.1.RELEASE]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
at com.sun.proxy.$Proxy465.query(Unknown Source) ~[na:na]
at io.choerodon.mybatis.pagehelper.PageInterceptor$DoPage.invoke(PageInterceptor.java:255) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:1.11.1.RELEASE]
at io.choerodon.mybatis.pagehelper.PageInterceptor.intercept(PageInterceptor.java:173) ~[hzero-starter-mybatis-mapper-1.11.1.RELEASE.jar:1.11.1.RELEASE]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
at com.sun.proxy.$Proxy465.query(Unknown Source) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) ~[mybatis-3.5.6.jar:3.5.6]
at org.hzero.boot.platform.lov.fuzzy.LovSearchSqlInterceptor.intercept(LovSearchSqlInterceptor.java:42) ~[hzero-boot-platform-1.11.1.RELEASE.jar:1.11.1.RELEASE]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
at com.sun.proxy.$Proxy465.query(Unknown Source) ~[na:na]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.6.jar:3.5.6]
... 161 common frames omitted
VO代码 :
@Id @GeneratedValue @JsonSerialize(using = ToStringSerializer.class) private Long id; @NotNull private String subjectId; private String subjectIdMeaning; private Integer status; private String statusMeaning; @NotBlank private List<String> categoryName;mapper.xml代码:
<sql id = "BaseSql"> ckc.id, ckc.subject_id, ckc.tenant_id, ckc.category_name, ckc.status, ckc.delete_flag, ckc.creation_date, ckc.created_by, ckc.last_updated_by, ckc.last_update_date, ckc.object_version_number </sql> <resultMap id="selectListVOMap" type="com.hucais.api.vo.KnowledgeCategoryListVO" autoMapping="true"> <id property="id" column="id" /> <result property="subjectId" column="subject_id"/> <collection property="categoryName" ofType="arraylist" select="selectName" column="subject_id" autoMapping="true"> </collection> </resultMap> <select id="selectName" resultType="arraylist"> select category_name from customized_knowledge_category where subject_id = #{subjectId} </select> <select id="selectListVO" resultMap="selectListVOMap"> select <include refid="BaseSql" /> from customized_knowledge_category ckc <where> and ckc.delete_flag = 0 <if test="categoryName != null"> and ckc.category_name like concat('%',#{categoryName,jdbcType = VARCHAR},'%') </if> </where> group by ckc.subject_id </select>
解决办法:
经过很长时间思考和debug,终于找到原因:
竟然是这个resultType类型设置错误,改为String即可
,当然这里是要跟你设置的返回类的变量的类型相关,到底是什么原因导致,我的技术太弱没有办法解决,仅仅提供自己的小小解决办法,可能会有所帮助!