mybatis criteria.valid

 

 mybatis 自带的框架,使用时有问题


在测试用例中直接调用selectPage 会出现错误:
     ### Error querying database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'criteria.valid'. Cause: org.apache.ibatis.ognl.NoSuchPropertyException: cn.com.baby.weibo.dao.ibatis.Critirias$Criteria.valid
     ### The error may exist in cn/com/baby/weibo/dao/ibatis/sqlmap/Tweet.xml
     ### The error may involve TweetMapper.selectByCritirias
     ### The error occurred while executing a query
     ### Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'criteria.valid'. Cause: org.apache.ibatis.ognl.NoSuchPropertyException: cn.com.baby.weibo.dao.ibatis.Critirias$Criteria.valid
          at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
          at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:61)
          at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:53)
          at cn.com.baby.weibo.dao.ibatis.IbatisBaseDao.list(IbatisBaseDao.java:92)
          at cn.com.baby.weibo.dao.ibatis.IbatisTweetDao.selectByCritirias(IbatisTweetDao.java:77)
          at cn.com.baby.weibo.dao.ibatis.IbatisTweetDao.selectPage(IbatisTweetDao.java:122)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
          at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
          at $Proxy18.selectPage(Unknown Source)
          at cn.com.baby.weibo.dao.ibatis.EntityManager.selectPage(EntityManager.java:186)
          ... 25 more
     Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'criteria.valid'. Cause: org.apache.ibatis.ognl.NoSuchPropertyException: cn.com.baby.weibo.dao.ibatis.Critirias$Criteria.valid
          at org.apache.ibatis.builder.xml.dynamic.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:20)
          at org.apache.ibatis.builder.xml.dynamic.IfSqlNode.apply(IfSqlNode.java:15)
          at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:14)
          at org.apache.ibatis.builder.xml.dynamic.ForEachSqlNode.apply(ForEachSqlNode.java:55)
          at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:14)
          at org.apache.ibatis.builder.xml.dynamic.TrimSqlNode.apply(TrimSqlNode.java:27)
          at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:14)
          at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:14)
          at org.apache.ibatis.builder.xml.dynamic.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:22)
          at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:198)
          at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:114)
          at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:83)
          at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:68)
          at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:59)
          ... 41 more
     Caused by: org.apache.ibatis.ognl.NoSuchPropertyException: cn.com.baby.weibo.dao.ibatis.Critirias$Criteria.valid
          at org.apache.ibatis.ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:115)
          at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1529)
          at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:84)
          at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:175)
          at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:213)
          at org.apache.ibatis.ognl.ASTChain.getValueBody(ASTChain.java:107)
          at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:175)
          at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:213)
          at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:314)
          at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:394)
          at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:435)
          at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:414)
          at org.apache.ibatis.builder.xml.dynamic.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:15)
          ... 54 more
     
     selectPage中有两次查询调用 
     this.selectByCritirias(critirias);
     this.countByCritirias(critirias);
     debug ibatis 源码发现,ibatis内嵌的ognl,在解析表达式criteria.valid,第一次解析出来 criteria.valid 的 readmethod, returnType, 并存入缓存map,第二次直接获得map的value时,丢失了readmethod。所以出现异常
     这个异常在测试系统和正式系统中都不会出现,怀疑是jdk的bug。
     如果需要在本地测试。可在调用 selectPage 前先调用一次selectByPrimaryKey。

你可能感兴趣的:(mybatis criteria.valid)