问题描述
- mybatis高手进,SOS-mybatis执行查询时返回入参。多谢
-
很怪异的问题,mybatis执行查询时,返回了原本的入参。这个问题偶然在服务器上出现过几次,本地开发环境从未出现过。小弟木有金币,只能道一声感谢!多谢!
代码如下:DAO:
try {
logger.info("---param: ID " + assReq.getId() + "--Code: " + assReq.getCode());
/**
* 怀疑是mybatis 缓存,将AssReq_findByKey 把SQL Key 值改为其他名字
* **/
Object res = this.queryForObject("AssReq_queryAssReq", assReq);
logger.info("----result: " + res);
return (AssessReq)res;
} catch (DAOException e) {
logger.error("---findAssReqByKey--DAOException ",e);
return null;
} catch (Exception e) {
logger.error("---findAssReqByKey--Exception ",e);
return null;
}SQL:
<select id="AssReq_queryAssReq" parameterType="com.aspire.mcts.ams.entity.ams.AssessReq" resultMap="AssReq_result" useCache="false"> select * from ams_assess <where> <if test="code != null and code != ''"> AND ASSESS_CODE = #{code} </if> <if test="id != null and id != ''"> AND ID = #{id} </if> </where> </select>
运行日志:
[INFO ]: 2014-11-28 13:18:56,239 :[com.aspire.mcts.ams.ass.dao.impl.AssReqDaoImpl] - ---param: ID 180--Code: null
[INFO ]: 2014-11-28 13:18:56,244 :[com.aspire.mcts.ams.ass.dao.impl.AssReqDaoImpl] - ----resutl: 180
[ERROR]: 2014-11-28 13:18:56,250 :[com.aspire.mcts.ams.ass.dao.impl.AssReqDaoImpl] - ---findAssReqByKey--Exceptionjava.lang.ClassCastException: java.lang.Integer cannot be cast to com.aspire.mcts.ams.entity.ams.AssessReq
at com.aspire.mcts.ams.ass.dao.impl.AssReqDaoImpl.findAssReqByKey(AssReqDaoImpl.java:86) ~[AssReqDaoImpl.class:na]
at com.aspire.mcts.ams.ass.service.impl.AssReqServiceImpl.findAssReqByKey(AssReqServiceImpl.java:55) [AssReqServiceImpl.class:na]
at com.aspire.mcts.ams.ass.service.impl.AssReqServiceImpl$$FastClassByCGLIB$$46a05f8d.invoke() [cglib-2.1.3.jar:na]
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) [cglib-2.1.3.jar:na]
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689) [org.springframework.aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [org.springframework.aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) [org.springframework.transaction-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [org.springframework.aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) [org.springframework.aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [org.springframework.aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) [org.springframework.aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at com.aspire.mcts.ams.ass.service.impl.AssReqServiceImpl$$EnhancerByCGLIB$$efff9e81.findAssReqByKey() [cglib-2.1.3.jar:na]
at com.aspire.mcts.ams.ass.action.AssReqAction.find(AssReqAction.java:38) [AssReqAction.class:na]