【问题标题】:Mybatis selectKey not returning sequence valueMybatis selectKey不返回序列值
【发布时间】:2017-05-18 00:42:01
【问题描述】:

我在 mybatis 中使用下面的插入查询。在 ibatis 中,同样的查询将 seq_consumer_id.nextval 返回给 java 中的调用方法,并将其插入到 consumer_id 列中。但是在 mybatis 中,该方法的返回值始终为 1(我假设它是插入的行数),尽管 consumer_id 列是从序列中正确更新的。难道我们不能生成密钥,插入它并返回给mybatis中的java类吗?

<insert id="insertConsumer" parameterType="com.enrollment.vo.ConsumerVO">
            <selectKey keyProperty="id" resultType="int" order="BEFORE">
                select seq_consumer_id.nextval as id from dual
            </selectKey>
                    insert into quotation_consumer (consumer_id, consumer_type, dob,  
                    create_date, ENROLLMENT_INDICATOR, QUOTE_ID,IS_PRIMARY) 
                    values(#{id},#{type.id}, #{birthdate, jdbcType=DATE}, default, #{enrollmentIndicator}, 
                    #{quoteId},#{isPrimary})

        </insert>

【问题讨论】:

    标签: java sql oracle mybatis ibatis


    【解决方案1】:

    该方法确实返回了受影响的行数。

    序列ID存储在com.enrollment.vo.ConsumerVOìd属性中作为参数传递。

    【讨论】:

      猜你喜欢
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      相关资源
      最近更新 更多