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

   ## 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 anymore 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?
   
   5.4.0
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   shardingSphere-jdbc 
   
   ### Expected behavior
   
   In one Transaction, before the insert data is commit in master db, the 
following read is also from **master**
   
   ### Actual behavior
   In one Transaction, before the insert data is commit in master db, the 
following read is from **salve**, which lead to an empty result.
   
   ### Reason analyze (If you can)
   the @Transactional annotation works, becase when an Exception occurs, the 
uncommit insert data is rollback。
   but it turns out that the shardingSphere still read from the slave in one 
transaction.
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   
   The code is as following:
   
   1. introduce the shardingSphere-jdbc 5.4.0
   ```
                <dependency>
                        <groupId>org.apache.shardingsphere</groupId>
                        <artifactId>shardingsphere-jdbc-core</artifactId>
                        <version>${shardingsphere.version}</version>
                </dependency>
   ```
   2. produce **shardingJdbcDatasource** bean in the way of java api
   
   ```
       @Bean
       public DataSource shardingSphereDataSource() throws SQLException {
           ReadwriteSplittingDataSourceRuleConfiguration dataSourceConfig =
                   new ReadwriteSplittingDataSourceRuleConfiguration(
                   SHARDING_DS_NAME, SHARDING_JDBC_MASTER, 
Arrays.asList(SHARDING_JDBC_SLAVE),
                   SHARDING_LOAD_BALANCE_NAME);
   
           Properties algorithmProps = new Properties();
           algorithmProps.setProperty(SHARDING_JDBC_SLAVE, "1");
           Map<String, AlgorithmConfiguration> algorithmConfigMap = new 
HashMap<>(1);
           algorithmConfigMap.put(SHARDING_LOAD_BALANCE_NAME, new 
AlgorithmConfiguration(SHARDING_LOAD_BALANCE_TYPE,
                   algorithmProps));
   
           ReadwriteSplittingRuleConfiguration ruleConfig =
                   new 
ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceConfig), 
algorithmConfigMap);
   
           Properties props = new Properties();
           props.setProperty("sql-show", showSql);
           return 
ShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(),
                   Collections.singleton(ruleConfig), props);
   
       }
   ```
   
   3. config sqlSessionFactory and transactionManager in spring-context.xml
   
        
   ```
        <bean id="transactionManager"
                
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                <property name="dataSource" ref="shardingSphereDataSource" />
        </bean>
   ```
   ```
        <bean id="sqlSessionFactory" 
class="org.mybatis.spring.SqlSessionFactoryBean">
                <property name="dataSource" ref="shardingSphereDataSource" />
                <property name="typeAliasesPackage" 
value="com.thinkgem.jeesite,com.saj.commons,com.saj.appapi" />
                <property name="typeAliasesSuperType"
                        
value="com.thinkgem.jeesite.common.persistence.BaseEntity" />
                <property name="mapperLocations" 
value="classpath:/mappings/**/*.xml" />
                <property name="configLocation" 
value="classpath:/mybatis-config.xml"></property>
        </bean>
   ```
   
   
   


-- 
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-unsubscr...@shardingsphere.apache.org.apache.org

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

Reply via email to