0

mysql テーブルの 1 つに値を挿入すると、次の例外が発生します。

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は自動インクリメントであり、主キーはnullではありません。私のマッパークラスでは

 <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>

そのため、すべてが正常な場合に上記の例外が発生する理由がわかりません。

何か見逃した場合はお知らせください。

4

1 に答える 1

0

MyBatisは、java.lang.Integerのパラメーターを使用してクラスFeedEntryのメソッド「setId」を呼び出そうとしています。その結果、ClassCastExceptionが発生します。

選択キーの結果タイプが正しいタイプになることを確認する必要があります。

于 2012-08-22T19:14:44.253 に答える