apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.81k stars 6.7k forks source link

How to configure a self incrementing primary key for a table without a table splitting policy ( 没有分表策略的表的,想用自增主键,如何配置 ) #14072

Closed robben009 closed 2 years ago

robben009 commented 2 years ago

Version information:

        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
            <version>4.0.0-RC2</version>
        </dependency>

config indo:

spring.shardingsphere.datasource.names = ds0

spring.shardingsphere.datasource.ds0.type = com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds0.driver-class-name = com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.ds0.jdbc-url =***
spring.shardingsphere.datasource.ds0.username = ***
spring.shardingsphere.datasource.ds0.password = ***

spring.shardingsphere.props.sql.show = true
spring.shardingsphere.sharding.tables.user.actual-data-nodes = ds0.user_${0..15}
spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column = u_id
spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression = user_${u_id % 19}
spring.shardingsphere.sharding.tables.user.key-generator.column = bos_id
spring.shardingsphere.sharding.tables.user.key-generator.type = SNOWFLAKE

As shown in the figure above, I just configure the user table as a sub table. Other tables in the same database are not divided into tables, but when I use mybaits plus to insert other tables, I find that shardingjdbc will automatically use the default snowflake algorithm as the primary key to insert into other tables.

How can I avoid this situation?

如上图配置,我仅仅是配置user表作为分表。同一数据库中其他表并没有分表,但是我结合mybaits-plus使用后,插入其他表的过程中,发现shardingJDBC会自动使用默认的雪花算法作为主键插入到其他表中。 我该如何避免这种情况?

terrymanu commented 2 years ago

ShardingSphere is faced for JDBC, we do not have more energy to deal with other additional ORM frameworks.