suikenungleung opened a new issue #12608:
URL: https://github.com/apache/shardingsphere/issues/12608
## Bug Report
### Development environment
Spring Boot: 2.5.4
MyBatis Spring Boot Starter: 2.2.0
ShardingSphere JDBC: 5.0.0-beta
MySQL: 8.0.23
### Which version of ShardingSphere did you use?
5.0.0-beta
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
shardingsphere-jdbc-core
### Expected behavior
Throw an exception.
The username field is unique, an exception should be thrown when adding
duplicates. It is normal when not using ShardingSphere.
```
org.springframework.dao.DuplicateKeyException:
### Error updating database. Cause:
java.sql.SQLIntegrityConstraintViolationException: Duplicate entry 'suikenung'
for key 'user.uk_username'
### The error may exist in file
[D:\Software\JetBrains\Projects\Java\sugus\sugus-system\target\classes\mapper\UserMapper.xml]
### The error may involve
com.lrq.sugus.system.mapper.UserMapper.insert-Inline
### The error occurred while setting parameters
### SQL: insert into `user` ( username,
`password`, enabled,
full_name,
email, mobile,
sex ) values ( ?,
?, ?,
?, ?,
?,
? )
### Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate
entry 'suikenung' for key 'user.uk_username'
; Duplicate entry 'suikenung' for key 'user.uk_username'; nested exception
is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry
'suikenung' for key 'user.uk_username'
```
### Actual behavior
When using ShardingSphere, nothing happened. And no exception is thrown.
### Reason analyze (If you can)
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
```
CREATE TABLE `user` (
...
UNIQUE INDEX `uk_username`(`username`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci
ROW_FORMAT = DYNAMIC;
```
```
<insert id="insert" keyProperty="id"
parameterType="com.lrq.sugus.system.dataobject.UserDO" useGeneratedKeys="true">
insert into `user` (username) values (#{username})
</insert>
```
### Example codes for reproduce this issue (such as a github link).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]