mybatis获取list的时候报错,请帮忙看看

bobosji 2013-05-30 11:11:23
Struts has detected an unhandled exception:
Messages:

smerp.domain.FactoryInfoUtil cannot be cast to org.apache.ibatis.session.RowBounds
### Error querying database. Cause: java.lang.ClassCastException: smerp.domain.FactoryInfoUtil cannot be cast to org.apache.ibatis.session.RowBounds ### The error may exist in file [D:\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\crms1\WEB-INF\classes\smerp\xml\FactoryInfoMapper.xml] ### The error may involve smerp.dao.FactoryInfoMapper.selectByExample ### The error occurred while executing a query ### Cause: java.lang.ClassCastException: smerp.domain.FactoryInfoUtil cannot be cast to org.apache.ibatis.session.RowBounds

FactoryInfo.xml:
  
...
<mapper namespace="smerp.dao.FactoryInfoMapper" >
<resultMap id="BaseResultMap" type="smerp.domain.FactoryInfo" >
<id column="FactoryID" property="factoryid" />
<result column="LongName" property="longname" />
<result column="ShortName" property="shortname" />
<result column="Address" property="address" />
<result column="OfficeNum1" property="officenum1" />
<result column="OfficeNum2" property="officenum2" />
<result column="MobileNum1" property="mobilenum1" />
<result column="MobileNum2" property="mobilenum2" />
<result column="Manager" property="manager" />
<result column="BankName1" property="bankname1" />
<result column="Account1" property="account1" />
<result column="BankName2" property="bankname2" />
<result column="Account2" property="account2" />
<result column="BankName3" property="bankname3" />
<result column="Account3" property="account3" />
<result column="BankName4" property="bankname4" />
<result column="Account4" property="account4" />
<result column="RATING" property="rating" />
<result column="UpdatedDate" property="updateddate" />
<result column="UpdatedBy" property="updatedby" />
</resultMap>
<sql id="Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
FactoryID, LongName, ShortName, Address, OfficeNum1, OfficeNum2, MobileNum1, MobileNum2,
Manager, BankName1, Account1, BankName2, Account2, BankName3, Account3, BankName4,
Account4, RATING, UpdatedDate, UpdatedBy
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="smerp.domain.FactoryInfoUtil" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from factoryinfo
<if test="_parameter != null" >
<include refid="Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
...
</mapper>


是想通过这个select查询返回一个List,请各位大神帮忙看看哪里有问题?多谢了
...全文
428 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
bobosji 2013-05-31
  • 打赏
  • 举报
回复
顶一下~~~~
七神之光 2013-05-30
  • 打赏
  • 举报
回复
bobosji 2013-05-30
  • 打赏
  • 举报
回复
这个can not cast不是普通的类型转换错误,而是smerp.domain.FactoryInfoUtil cannot be cast to org.apache.ibatis.session.RowBounds,我很奇怪。 这个smerp.domain.FactoryInfoUtil带的参数在where里面有用到。 请继续帮找虫
kittaaron 2013-05-30
  • 打赏
  • 举报
回复
检查一下,sql里查询出来的字段,跟楼主自己定义的类型各个属性是不是都是匹配的吧,错误很明显就是can not cast,就是查出来的内容不能cast成楼主定义的类型! 有一个地方没太明白: <select id="selectByExample" resultMap="BaseResultMap" parameterType="smerp.domain.FactoryInfoUtil" > 这里的select语句 parameterType是干什么用的呢?好像语句里并没有需要smerp.domain.FactoryInfoUtil这个类型的动态参数啊
bobosji 2013-05-30
  • 打赏
  • 举报
回复
MyBatis工作流程 (1)加载配置并初始化 触发条件:加载配置文件 配置来源于两个地方,一处是配置文件,一处是Java代码的注解,将SQL的配置信息加载成为一个个MappedStatement对象(包括了传入参数映射配置、执行的SQL语句、结果映射配置),存储在内存中。 (2)接收调用请求 触发条件:调用Mybatis提供的API 传入参数:为SQL的ID和传入参数对象 处理过程:将请求传递给下层的请求处理层进行处理。 (3)处理操作请求 触发条件:API接口层传递请求过来 传入参数:为SQL的ID和传入参数对象 处理过程: (A)根据SQL的ID查找对应的MappedStatement对象。 (B)根据传入参数对象解析MappedStatement对象,得到最终要执行的SQL和执行传入参数。 (C)获取数据库连接,根据得到的最终SQL语句和执行传入参数到数据库执行,并得到执行结果。 (D)根据MappedStatement对象中的结果映射配置对得到的执行结果进行转换处理,并得到最终的处理结果。 (E)释放连接资源。 (4)返回处理结果将最终的处理结果返回。 看来我的SQL语句在第一步就未能正确加载,不过后面报的错也是奇怪,继续跟 同时求大神指点
bobosji 2013-05-30
  • 打赏
  • 举报
回复
兄弟,谢谢你了,你很热心,不过解决不了我的问题 <sql id="Base_Column_List" > FactoryID, LongName, ShortName, Address, OfficeNum1, OfficeNum2, MobileNum1, MobileNum2, Manager, BankName1, Account1, BankName2, Account2, BankName3, Account3, BankName4, Account4, RATING, UpdatedDate, UpdatedBy </sql> 我现在把这里面的column list都搬到selectByExample里面去了 再顶顶
  • 打赏
  • 举报
回复
上面问你参数类型是否是FactoryInfoUtil? 还有select <if test="distinct" > distinct </if> <include refid="Base_Column_List" /> from factoryinfo 你select 后面是个空的东西的
bobosji 2013-05-30
  • 打赏
  • 举报
回复
配置parameterType="smerp.domain.FactoryInfoUtil" 主要是用来传递查询条件
bobosji 2013-05-30
  • 打赏
  • 举报
回复
哦对了,现在已经修改成 <select id="selectByExample" resultType="smerp.domain.FactoryInfo" parameterType="smerp.domain.FactoryInfoUtil" > 报错还是一样的
  • 打赏
  • 举报
回复
你先说说你配置parameterType="smerp.domain.FactoryInfoUtil" 有和用意。
bobosji 2013-05-30
  • 打赏
  • 举报
回复
我现在已经简化到这个样子: <select id="selectByExample" resultMap="BaseResultMap" parameterType="smerp.domain.FactoryInfoUtil" > select <include refid="Base_Column_List" /> from factoryinfo </select> 仍然不过,跟踪了一下源码,发现是session获取到configuration后在mappedStatments里面没有找到key为smerp.dao.FactoryInfoMapper.selectByExample的对象,同一个xml里面其他的语句有的有,有的就没有。这个selectByExample在没有的里面,至于具体为什么会这样,还需要继续跟。 有哪位熟悉源码的大神说说看为什么?确实是配置语句有问题吗?--我用文本对比工具都比对过了跟其他能够出现在mappedStatements里面的语句做了对比,发现不了太多区别,或者还是别的原因?
  • 打赏
  • 举报
回复
<select id="selectByExample" resultMap="BaseResultMap" parameterType="smerp.domain.FactoryInfoUtil" > select <if test="distinct" > distinct </if> <include refid="Base_Column_List" /> from factoryinfo <if test="_parameter != null" > <include refid="Where_Clause" /> </if> <if test="orderByClause != null" > order by ${orderByClause} </if> </select> parameterType表示参数类型,你的orderByClause是FactoryInfoUtil否?
bobosji 2013-05-30
  • 打赏
  • 举报
回复
为什么smerp.domain.FactoryInfoUtil要cast成org.apache.ibatis.session.RowBounds?
bobosji 2013-05-30
  • 打赏
  • 举报
回复
to楼上:看了又看,应该是没错
  • 打赏
  • 举报
回复
smerp.domain.FactoryInfoUtil cannot be cast to org.apache.ibatis.session.RowBounds <select id="selectByExample" resultMap="BaseResultMap" parameterType="smerp.domain.FactoryInfoUtil" > 写错了吧

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧