Search code examples
javasqloraclemybatisibatis

Mybatis selectKey not returning sequence value


I'm using the below insert query in mybatis. In ibatis, the same query returned seq_consumer_id.nextval to the calling method in java, and inserted the same into the consumer_id column. But in mybatis, return value of the method is always 1 (I'm assuming its the no of rows inserted), though consumer_id column is correctly updated from sequence. Can't we generate the key, insert it and return the same to java class in mybatis ?

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

Solution

  • Indeed the method returns the number of affected rows.

    Sequence id is stored in ìd property of com.enrollment.vo.ConsumerVO passed as parameter.