Table primary key self-growth mybatis Insert data error

Source: Internet
Author: User

In the process of developing with MyBatis, when you encounter inserting a record into a database table, the data is inserted incorrectly, and if you determine that it is the cause of the primary key, it is similar to the following error message:

And your intention is the primary key automatically grow, then, you can refer to the following methods to try to solve:

First step: Set the primary key to self-grow in the configuration (database I'm using MySQL)

If you are using the MyBatis Auto-generated INSERT statement, in addition to setting the usegeneratedkeys= "true" given above, you also need to remove the red part as shown, which is a piece of code that queries the maximum value of the primary key.

If not, you should check your database table for the primary key setting and whether it is an auto-grow setting.

You can add auto_increment after the primary key in the SQL statement.

If you are using the tool "Navicat for MySQL", such as I want to set the primary key of Tb-device_basic table to autogrow, click "Design Table", then "Auto Grow" tick, then try again.

Table primary key self-growth mybatis Insert data error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.