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 2022/10/10 06:44:20 UTC

[GitHub] [shardingsphere] zhyyu opened a new issue, #8560: h2 database ShardingSphereMetaData schema incomplete, Key GeneratorConfig don't work

zhyyu opened a new issue, #8560:
URL: https://github.com/apache/shardingsphere/issues/8560

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   ```
       <dependency>
               <groupId>org.apache.shardingsphere</groupId>
               <artifactId>sharding-jdbc-core</artifactId>
               <version>4.1.1</version>
           </dependency>
   ```
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   - ShardingSphere-JDBC
   
   ### Expected behavior
   - get complete schema data (so can use keyGenerate)
   - insert row using generated key
   
   ### Actual behavior
   - schema tableMeta don't have generated key (when using mysql dataSource is ok, but h2 database wrong)
   - sql exception : org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [insert into test_snow_flake (name) values (?)]; NULL not allowed for column "ID"; SQL statement:
   
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   - /resouces/schema.sql
   ```
   CREATE TABLE `test_snow_flake0`
   (
       `id`   bigint,
       `name` varchar(45) NOT NULL,
       PRIMARY KEY (`id`)
   );
   
   
   CREATE TABLE `test_snow_flake1`
   (
       `id`   bigint,
       `name` varchar(45) NOT NULL,
       PRIMARY KEY (`id`)
   );
   ```
   
   - dataSource config
   ```
     @Bean
       public DataSource shardingJdbcSnowFlakeDataSource() throws SQLException {
           // 配置真实数据源
           Map<String, DataSource> dataSourceMap = new HashMap<>();
   
           // 配置第一个数据源
   //        HikariDataSource dataSource1 = getMysqlDataSource();
           HikariDataSource dataSource1 = getH2DataSource();
           dataSourceMap.put("test_schema_1", dataSource1);
   
           // 配置 test_snow_flake 表规则
           TableRuleConfiguration testTableTableRuleConfig = new TableRuleConfiguration("test_snow_flake","test_schema_1.test_snow_flake${0..1}");
   
           // 自定义分片规则
           StandardShardingStrategyConfiguration standardShardingStrategyConfiguration = new StandardShardingStrategyConfiguration("name", new PreciseShardingAlgorithm() {
               @Override
               public String doSharding(Collection availableTargetNames, PreciseShardingValue shardingValue) {
                   String name = (String) shardingValue.getValue();
                   if (StringUtils.isEmpty(name)) {
                       return (String) availableTargetNames.stream().findFirst().get();
                   }
   
                   if (name.startsWith("a")) {
                       return "test_snow_flake0";
                   }
   
                   return "test_snow_flake1";
               }
           });
           testTableTableRuleConfig.setTableShardingStrategyConfig(standardShardingStrategyConfiguration);
   
           // 自定义分布式主键
           testTableTableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "id"));
   
           // 配置分片规则
           ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
           shardingRuleConfig.getTableRuleConfigs().add(testTableTableRuleConfig);
   
           // 获取数据源对象
           Properties properties = new Properties();
           properties.setProperty("sql.show", "true");
           DataSource dataSource = ShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig, properties);
           return dataSource;
       }
   
       private HikariDataSource getMysqlDataSource() {
           HikariDataSource dataSource1 = new HikariDataSource();
           dataSource1.setDriverClassName("com.mysql.jdbc.Driver");
           dataSource1.setJdbcUrl("jdbc:mysql://localhost:3306/test_schema_1");
           dataSource1.setUsername("root");
           dataSource1.setPassword("xxxx");
           return dataSource1;
       }
   
       private HikariDataSource getH2DataSource() {
           HikariDataSource dataSource1 = new HikariDataSource();
           dataSource1.setDriverClassName("org.h2.Driver");
           dataSource1.setJdbcUrl("jdbc:h2:mem:test_schema_1");
           dataSource1.setUsername("sa");
           return dataSource1;
       }
   ```
   
   - test case
   ```
   @RunWith(SpringRunner.class)
   @SpringBootTest
   public class TestSnowFlakeDAOTest {
   
       @Autowired
       private TestSnowFlakeDAO testSnowFlakeDAO;
   
       @Test
       public void testInsert() {
           TestSnowFlakeDAO.TestSnowFlakeRow testSnowFlakeRow = new TestSnowFlakeDAO.TestSnowFlakeRow();
           testSnowFlakeRow.setName("name0");
           Integer insertCount = testSnowFlakeDAO.insert(testSnowFlakeRow);
           assertEquals(insertCount, Integer.valueOf(1));
   
           TestSnowFlakeDAO.TestSnowFlakeRow testSnowFlakeRow2 = new TestSnowFlakeDAO.TestSnowFlakeRow();
           testSnowFlakeRow2.setName("aname0");
           testSnowFlakeDAO.insert(testSnowFlakeRow2);
       }
   
   }
   ```
   
   
   
   
   
   
   ### Example codes for reproduce this issue (such as a github link).
   [github repo](https://github.com/zhyyu/learn-sharding-jdbc)


-- 
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: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] github-actions[bot] closed issue #8560: h2 database ShardingSphereMetaData schema incomplete, Key GeneratorConfig don't work

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed issue #8560: h2 database ShardingSphereMetaData schema incomplete, Key GeneratorConfig don't work
URL: https://github.com/apache/shardingsphere/issues/8560


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] h2 database ShardingSphereMetaData schema incomplete, Key GeneratorConfig don't work [shardingsphere]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #8560:
URL: https://github.com/apache/shardingsphere/issues/8560#issuecomment-2026023443

   There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] github-actions[bot] commented on issue #8560: h2 database ShardingSphereMetaData schema incomplete, Key GeneratorConfig don't work

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #8560:
URL: https://github.com/apache/shardingsphere/issues/8560#issuecomment-1272350979

   Hello , this issue has not received a reply for several days.
   This issue is supposed to be closed.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org