Mybatis 3 bug

Source: Internet
Author: User

Mybatis 3 bug

Author: chszs

Reprinted please indicate the source!

Version: mybatis 3.0.4
BUG: the insert statement does not correctly return the value of the auto-increment field. MySQL database script:
CREATE TABLE `worker` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `pin` varchar(64) DEFAULT NULL,  `firstname` varchar(64) DEFAULT NULL,  `lastname` varchar(64) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
Corresponding sqlmap ing <insert id = "addworker" parametertype = "worker" usegeneratedkeys = "true" keyproperty = "ID"> <selectkey resulttype = "int" keyproperty = "ID" Order = "after"> select last_insert_id () as value </selectkey> insert into worker (pin, firstname, lastname) values (# {pin}, # {firstname}, # {firstname}) </Insert>
The corresponding entity-class worker. Java, Dao, interface, and configuration are omitted ......
The result of execution is that only 1 is returned and the value of the Self-incrementing field is not obtained.

----------------
The alternative solution to this bug is:
Specifically configure for ID retrieval:
<Select id = "getworkerid" resulttype = "int">
Select last_insert_id ()
</SELECT>
It is equivalent to executing two SQL statements to obtain the required id value. [E01]

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.