New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error occurred when I try to "INSERT INTO ~ ON DUPLICATE KEY UPDATE" with useGeneratedKeys. #1523
Comments
|
Hi @ApplePedlar , I cannot reproduce this. Could you provide a small reproduce executable project via GitHub? |
|
Me neither (tested with MySQL 5.6.43 and Connector/J 8.0.15). Here's the project I used (docker required). |
|
The description matches this Connector/J bug. UPDATE: |
|
Thank you for creating a test project. The bug was reproduced using mariadb-connector. |
|
Thank you for the update, @ApplePedlar ! I could verify the problem. As it's the driver's bug, I reported it to MariaDB JIRA. |
|
Hi @ApplePedlar , p.s. |
* master: (616 commits) Fix trivial grammer mistake Trivial doc correction Add 'defaultNetworkTimeout' to PooledDataSource and UnpooledDataSource Update README.md Follow-up to mybatis#1517 Change to use try-with-resources on doc New versions available. fixes mybatis#1523 Better error message when too many keys are generated Minor refactoring. Reuse PostgreSQL container without restarting Replace postgresql-embedded with Testcontainers Added Stack Overflow as a place for questions Add `.editorconfig` to maintain consistent coding styles [maven-release-plugin] prepare for next development iteration [maven-release-plugin] prepare release mybatis-3.5.1 [ci] Cache maven dependencies. Added edge case tests provided by @kdubb Add comment for derby Revert "Upgrade to derby 10.15.1.3" Upgrade to assertj 3.12.2 ... # Conflicts: # pom.xml # src/main/java/org/apache/ibatis/binding/MapperMethod.java # src/main/java/org/apache/ibatis/binding/MapperProxyFactory.java # src/main/java/org/apache/ibatis/binding/MapperRegistry.java # src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java # src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java # src/main/java/org/apache/ibatis/plugin/Plugin.java # src/main/java/org/apache/ibatis/reflection/Reflector.java # src/main/java/org/apache/ibatis/session/Configuration.java # src/main/java/org/apache/ibatis/session/SqlSession.java # src/main/java/org/apache/ibatis/session/TransactionIsolationLevel.java # src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java # src/main/java/org/apache/ibatis/transaction/Transaction.java # src/main/java/org/apache/ibatis/transaction/TransactionFactory.java # src/main/java/org/apache/ibatis/transaction/jdbc/JdbcTransaction.java # src/main/java/org/apache/ibatis/transaction/managed/ManagedTransaction.java # src/main/java/org/apache/ibatis/type/ArrayTypeHandler.java # src/main/java/org/apache/ibatis/type/BaseTypeHandler.java # src/main/java/org/apache/ibatis/type/SimpleTypeRegistry.java # src/main/java/org/apache/ibatis/type/TypeAliasRegistry.java # src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java
|
This is just a heads up. This particular issue (CONJ-698) will be resolved in MariaDB Connector/J 2.5.0. As a result, with MariaDB Connector/J 2.5.0, <insert id="insertUpdate" useGeneratedKeys="true" keyProperty="id">
INSERT INTO Animal (name) VALUES
<foreach var="animal" items="list" separator=",">
(#{animal.name})
</foreach>
</insert>[EDIT] The behavior change mentioned above was 'corrected' as a regression in MariaDB Connector/J 2.5.1 (CONJ-735). |
|
MariaDB Java Connector 2.5.0 is released. |
|
I have a similar issue, which can be reproduced under these conditions: mysql-connector-java: 5.1.40 <insert id="insertShopInfo" parameterType="com.mycompany.po.ShopInfo"
useGeneratedKeys="true" keyProperty="id">
insert into shop_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="poiId != null">
poi_id,
</if>
<if test="bizAccountId != null">
biz_account_id,
</if>
<if test="userType != null">
user_type,
</if>
<if test="pointName != null">
point_name,
</if>
<if test="brandName != null">
brand_name,
</if>
<if test="district != null">
district,
</if>
<if test="brandId != null">
brand_id,
</if>
<if test="typeId != null">
type_id,
</if>
<if test="bareaId != null">
barea_id,
</if>
<if test="locationId != null">
location_id,
</if>
<if test="address != null">
address,
</if>
<if test="phone != null">
phone,
</if>
<if test="mergeId != null">
merge_id,
</if>
<if test="bareaName != null">
barea_name,
</if>
<if test="typeName != null">
type_name,
</if>
<if test="openInfo != null">
open_info,
</if>
<if test="pricePerson != null">
price_person,
</if>
<if test="typeHierarchy != null">
type_hierarchy,
</if>
<if test="isForeign != null">
is_foreign,
</if>
<if test="geo != null">
geo,
</if>
<if test="status != null">
status,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="modifyTime != null">
modify_time,
</if>
<if test="cityLocationId != null">
city_location_id,
</if>
<if test="cityName != null">
city_name,
</if>
<if test="provinceName != null">
province_name,
</if>
<if test="provinceId != null">
province_id,
</if>
<if test="email != null">
email,
</if>
<if test="hasEat != null">
has_eat,
</if>
<if test="dispatchTypes != null">
dispatch_types,
</if>
<if test="poiType != null">
poi_type,
</if>
<if test="locationName != null">
location_name,
</if>
<if test="encryptWay != null">
encrypt_way,
</if>
<if test="phoneToken != null">
phone_token,
</if>
<if test="tokenEncryptedPhone != null">
token_encrypted_phone,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="poiId != null">
#{poiId,jdbcType=BIGINT},
</if>
<if test="bizAccountId != null">
#{bizAccountId,jdbcType=BIGINT},
</if>
<if test="userType != null">
#{userType,jdbcType=INTEGER},
</if>
<if test="pointName != null">
#{pointName,jdbcType=VARCHAR},
</if>
<if test="brandName != null">
#{brandName,jdbcType=VARCHAR},
</if>
<if test="district != null">
#{district,jdbcType=VARCHAR},
</if>
<if test="brandId != null">
#{brandId,jdbcType=INTEGER},
</if>
<if test="typeId != null">
#{typeId,jdbcType=INTEGER},
</if>
<if test="bareaId != null">
#{bareaId,jdbcType=INTEGER},
</if>
<if test="locationId != null">
#{locationId,jdbcType=INTEGER},
</if>
<if test="address != null">
#{address,jdbcType=VARCHAR},
</if>
<if test="phone != null">
#{phone,jdbcType=VARCHAR},
</if>
<if test="mergeId != null">
#{mergeId,jdbcType=INTEGER},
</if>
<if test="bareaName != null">
#{bareaName,jdbcType=VARCHAR},
</if>
<if test="typeName != null">
#{typeName,jdbcType=VARCHAR},
</if>
<if test="openInfo != null">
#{openInfo,jdbcType=VARCHAR},
</if>
<if test="pricePerson != null">
#{pricePerson,jdbcType=INTEGER},
</if>
<if test="typeHierarchy != null">
#{typeHierarchy,jdbcType=VARCHAR},
</if>
<if test="isForeign != null">
#{isForeign,jdbcType=INTEGER},
</if>
<if test="geo != null">
#{geo,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="modifyTime != null">
#{modifyTime,jdbcType=TIMESTAMP},
</if>
<if test="cityLocationId != null">
#{cityLocationId,jdbcType=INTEGER},
</if>
<if test="cityName != null">
#{cityName,jdbcType=VARCHAR},
</if>
<if test="provinceName != null">
#{provinceName,jdbcType=VARCHAR},
</if>
<if test="provinceId != null">
#{provinceId,jdbcType=INTEGER},
</if>
<if test="email != null">
#{email,jdbcType=VARCHAR},
</if>
<if test="hasEat != null">
#{hasEat,jdbcType=BIT},
</if>
<if test="dispatchTypes != null">
#{dispatchTypes,jdbcType=VARCHAR},
</if>
<if test="poiType != null">
#{poiType,jdbcType=INTEGER},
</if>
<if test="locationName != null">
#{locationName,jdbcType=VARCHAR},
</if>
<if test="encryptWay != null">
#{encryptWay,jdbcType=INTEGER},
</if>
<if test="phoneToken != null">
#{phoneToken,jdbcType=VARCHAR},
</if>
<if test="tokenEncryptedPhone != null">
#{tokenEncryptedPhone,jdbcType=VARCHAR},
</if>
</trim>
ON DUPLICATE KEY UPDATE
address = VALUES(address),
point_name = VALUES(point_name),
location_id = VALUES(location_id),
phone = VALUES(phone),
type_name = VALUES(type_name),
email =VALUES(email),
has_eat = VALUES(has_eat),
dispatch_types = VALUES(dispatch_types),
modify_time = VALUES(modify_time),
encrypt_Way = VALUES(encrypt_way),
phone_token = VALUES(phone_token),
token_encrypted_phone = VALUES(token_encrypted_phone)
</insert>shopInfoExtMapper.insertShopInfo(shopInfo)The error stacktrace is:
I know this issue is closed, but this is only lead I can found on Github. I can open a new issue if necessary. |
|
Hello @magicliang , |
Thanks for replying. Our DB version is 5.7.21-21-log(but it is a percona version, not normal community version). It is very hard to provide a complete demo to reproduce this problem, because we are using a non-open-sourcing technical stack which uses non-standar jdbc middleware. After some digging, we think the root cause of this case is insertion with "update on duplicate key" creates 2 affected rows, which generates 2 auto_increment ids. I will try to prove it and make a simple demo later. Let's see what happens then. |
I have also encountered this problem. Has this problem been solved? |
|
Hello @anhao , |
|
I'm going to lock this issue. Read my earlier comment explaining the flip-flops in MariaDB Connector/J. |
MyBatis version
3.5.1
Database vendor and version
MySQL 5.6
Test case or example project
Table scheme
model (sample.Animal)
mapper interface (sample.AnimalMapper)
mapper xml (sample/AnimalMapper.xml)
test case (sample.AnimalMapperTest)
Steps to reproduce
run test.
Expected result
Name changes from wolf to dog.
Actual result
Error occurred.
Version 3.4.6 and 3.5.0 work fine.
Related Issues
The text was updated successfully, but these errors were encountered: