Alex Bondar Alex Bondar - 23 days ago 9
MySQL Question

MyBatis always returns 1

I am trying to get last inserted key after insert using mybatis.

<insert id="insertOrUpdateUser" useGeneratedKeys="true" keyColumn="id"
keyProperty="user.id" >
INSERT INTO
user (username, password)
VALUES (
#{user.username},
#{user.password}
)
ON DUPLICATE KEY UPDATE
username = #{user.username},
password = #{user.password}
</insert>


Looks like I have everything to get last generated id but I always get 1.What is wrong?

Answer Source

id automatically returned with your model's id field user.id, 1 is inserted row count

Please check this