首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在mysql表中插入记录时出现异常

在mysql表中插入记录时出现异常
EN

Stack Overflow用户
提问于 2012-08-21 18:16:13
回答 1查看 527关注 0票数 0

我正在向其中一个mysql表插入值,并收到以下异常:

代码语言:javascript
复制
Could not set property 'id' of 'class com.mycom.myproject.db.mybatis.model.FeedEntry' with    value '2' Cause: java.lang.IllegalArgumentException: java.lang.ClassCastException@175e216] with root cause.

正在表中成功插入记录。在我的表中,id是自动递增的,主键是不为空的。在我的mapper类中我有

代码语言:javascript
复制
 <insert id="insertSelective" parameterType="com.mycom.myproject.db.mybatis.model.Category" >
<!--
  WARNING - @mbggenerated
  This element is automatically generated by MyBatis Generator, do not modify.
  This element was generated on Fri Aug 10 11:40:59 BST 2012.
-->
<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
  SELECT LAST_INSERT_ID()
</selectKey>
insert into category
<trim prefix="(" suffix=")" suffixOverrides="," >
  <if test="fSourceId != null" >
    f_source_id,
  </if>
  <if test="userId != null" >
    user_id,
  </if>
  <if test="author != null" >
    author,
  </if>
  <if test="name != null" >
    name,
  </if>

</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
  <if test="fSourceId != null" >
    #{fSourceId,jdbcType=INTEGER},
  </if>
  <if test="userId != null" >
    #{userId,jdbcType=BIGINT},
  </if>
  <if test="author != null" >
    #{author,jdbcType=VARCHAR},
  </if>
  <if test="name != null" >
    #{name,jdbcType=VARCHAR},
  </if>      
</trim>

所以我不明白为什么在一切正常的情况下我会得到上面的异常。

如果我错过了什么,请告诉我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-23 03:14:44

MyBatis正在尝试使用参数java.lang.Integer调用类FeedEntry上的方法"setId“,结果是一个ClassCastException。

您需要确保select键的结果类型是正确的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12052758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档