Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ljheee/article/details/84483693
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '__frch_criterion_1' in 'class com.xxxx.dao.domain.XxxExample'
at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:409)
at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:164)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:162)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:49)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.reflection.MetaObject.metaObjectForProperty(MetaObject.java:145)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:115)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:219)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:135)
at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)

背景

出现该异常的是SSM工程,使用原生mybatis-generator 给业务实体类(Entity,POJO)生成了对应的XxxExample类,并且在mybatis-generator.xml中使用了
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"/>

有过相关开发经验的同学一定都知道,为业务实体类 生成了对应的XxxExample类,就是为了简化SQL查询,使用RowBoundsPlugin就是在查询时,能方便的进行分页。有了上面这个2个工具,就能方便的执行xxxMapper.selectByExampleWithRowbounds(example, rowBounds)进行分页+条件查询了。
而这个 异常,就是由于这个RowBoundsPlugin分页插件导致的。

经过反复试验发现:是把工程的mybatis依赖提升到3.4.2时 出现的该异常,也就是:

  • mybatis.generator 的版本1.3.5
  • mybatis 的版本3.4.2
  • mybatis-spring 的版本1.3.0
    这套依赖下,RowBoundsPlugin分页插件出现了该异常。

于是修改工程pom.xml,降低mybatis版本到之前能正常运行的

  • mybatis.generator 的版本1.3.5
  • mybatis 的版本3.2.3
  • mybatis-spring 的版本1.2.2
    回退mybatis 到这套版本时,就能跟之前一样运行了。后来发现降低mybatis版本到3.2.x以前的,也能运行。

出现该问题,也折腾了半天。后来请教了一位资深mybatis研究者(一个mybatis插件的开源者),目前市面上的mybatis分页插件大体分为2类,一类是支持动态SQL的,如PageHelper;一类是不支持动态SQL的,如RowBoundsPlugin;区别在于如何完成动态参数设置。
我们知道mybatis插件本质都是拦截器,它在mybatis Executor执行SQL之前拦截SQL,设置分页参数等,凡是不支持动态SQL的的分页插件,都会出现该异常

在百度搜索这个异常,发现国内很多使用分页插件的同学 确实出现的这个问题。而且经过这次自己碰到,试验发现有些分页插件能否“正常工作” 还和mybatis版本有关;
为了使原先引入分页插件的代码正常工作,而回退整个工程的mybatis版本还是不推荐的,除非万不得已。
在搭建骨架选择工具时,应该考虑到引入新的插件对原有工程项目的影响,以及这个插件的不足。

最后为大家推荐一个好用的mybatis辅助工具https://www.jianshu.com/p/5f84624e96bc,不是做分页用的,而是避免为每一个实体类 都生成对应的XxxExample,能做到通用。

猜你喜欢

转载自blog.csdn.net/ljheee/article/details/84483693