You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/05/30 18:37:45 UTC
[GitHub] [shardingsphere] jukai5501 opened a new issue #5858: When batch inserting, only the primary key of the first data is returned
jukai5501 opened a new issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858
## Bug Report
**For English only**, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
- Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
Please pay attention on issues you submitted, because we maybe need more details.
If no response **more than 7 days** and we cannot reproduce it on current information, we will **close it**.
Please answer these questions before submitting your issue. Thanks!
### Which version of ShardingSphere did you use?
4.1.0
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
### Expected behavior
When inserting in batch, return the primary key of each piece of data
### Actual behavior
When batch inserting, only the primary key of the first data is returned
### Reason analyze (If you can)
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
Batch insert 2 pieces of data, only the first one returns the primary key. "carediaryid" is the primary key.
`
<insert id="insertAll"
parameterType="com.test.CareDiaryDO"
useGeneratedKeys="true"
keyProperty="careDiaryId">
insert into care_diary (care_diary_type_cd, creator_type, description, status_cd, create_dt)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.careDiaryTypeCd,jdbcType=CHAR},
#{item.creatorType,jdbcType=CHAR},
#{item.description,jdbcType=VARCHAR},
#{item.statusCd,jdbcType=CHAR},
#{item.createDt,jdbcType=TIMESTAMP}, )
</foreach>
</insert>
`
`
spring:
shardingsphere:
sharding:
default-data-source-name: ds
tables:
care_diary:
key-generator:
column: care_diary_id
type: snowflake
`
### 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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] yu199195 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
yu199195 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636575324
@jukai5501 i test and debug This function of Distributed primary key generation,it work well, mybe you config have some error ,log sharding config on the console.,Here is the reference :(Please be careful to align ,In the configuration you mentioned above, there may be errors)
```
spring:
shardingsphere:
sharding:
tables:
t_order:
actualDataNodes: ds_$->{0..1}.t_order
keyGenerator:
column: order_id
props:
worker.id: '123'
type: SNOWFLAKE
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] jukai5501 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
jukai5501 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636911976
@yu199195 I don't have a split table. I only use a distributed primary key for a table.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] jukai5501 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
jukai5501 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636442633
@yu199195 It is the log sql. You can try to create a table, then insert data in batches, and see that each record has a return primary key.
```
2020-05-31 16:48:37.704 INFO 22293 [127.0.0.1:10101] --- [io-10101-exec-1] ShardingSphere-SQL : Actual SQL: ds ::: insert into care_diary (scare_diary_type_cd,
creator_type, description, status_cd,
create_dt, care_diary_id)
values
(?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?) ::: [111, T, null, 00000, 2020-05-31 16:48:37.552, 473894769873911809, 111, T, null, 00000, 2020-05-31 16:48:37.554, 473894769869717504]
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] jukai5501 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
jukai5501 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-637418111
@yu199195 Hi,this is complete sharding configuration.
```
spring:
shardingsphere:
props:
sql.show: true
query.with.cipher.column: true
datasource:
names: ds
ds:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/${MYSQL_DB:bs}?serverTimezone=Asia/Shanghai
username: ${MYSQL_USER:bs}
password: ${MYSQL_PASSWORD:bs12345}
hikari:
minimum-idle: 60
maximum-pool-size: 60
idle-timeout: 60000
max-lifetime: 1800000
connection-timeout: 3000
pool-name: BabyshowHikariCP
connection-test-query: SELECT 1
sharding:
default-data-source-name: ds
tables:
care_diary:
key-generator:
column: care_diary_id
type: snowflake
system_user:
key-generator:
column: system_user_id
type: snowflake
encrypt-rule:
tables:
system_user:
columns:
credential:
encryptor: bs_encrypt
cipherColumn: credential
encryptors:
bs_encrypt:
type: aes
props:
aes.key.value: ${SHARDING_ENCRYPTOR_AES_PWD:2020$bs#0105}
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu closed issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] jukai5501 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
jukai5501 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636450521
@yu199195 This is my code ` int insertAll(List<CareDiaryDO> record);`, I want to get every ‘ careDiaryId’ in the parameter ‘record’, and 'careDiaryId' is generated through the distributed primary key of shardingsphere.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu closed issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] yu199195 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
yu199195 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636448570
@jukai5501 you want to collect List<PK> ,in you mybatis mapper? for like this
```
List<Strig> batchInsert(T t)
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] yu199195 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
yu199195 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636424647
> I want to use shardingsphere's distributed primary key
i know,can you log sql? it will contains `care_diary_id`
```
insert into care_diary (care_diary_id,care_diary_type_cd, creator_type, description, status_cd, create_dt)
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] yu199195 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
yu199195 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636420834
`care_diary_id` should be In your insert statement, If you use mybatis, you can set it to auto generate .
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] jukai5501 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
jukai5501 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636493287
@yu199195 You are welcome, waiting for your reply.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] jukai5501 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
jukai5501 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636421640
> `care_diary_id` should be In your insert statement, If you use mybatis, you can set it to auto generate .
I want to use shardingsphere's distributed primary key
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] jukai5501 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
jukai5501 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-639970407
@yu199195 I use spring's native datasource to perform bulk insertion. The primary key of the table is set to grow automatically. You can get the value generated by the primary key in the input parameter, but you can't get the distributed ID generated by it through shardingsphere.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] yu199195 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
yu199195 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-637218820
@jukai5501 hi, distributed primary key Designed for sharding table. if you not work, could you show complete sharding configuration?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] yu199195 commented on issue #5858: When batch inserting, only the primary key of the first data is returned
Posted by GitBox <gi...@apache.org>.
yu199195 commented on issue #5858:
URL: https://github.com/apache/shardingsphere/issues/5858#issuecomment-636466103
@jukai5501 i know you mean, batch insert data, and the primary key of sharing-shpere auto generation , Later we need to verify that the problem exists, thanks.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org