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

   ### Which version of ShardingSphere did you use?
   
   4.1.0
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-JDBC
   
   ### Expected behavior
   
   Read the data immediately after writing, expecting to query from the master 
database
   ### Actual behavior
   
   query from the slave database
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   service query by slave database:
   
   
![image](https://user-images.githubusercontent.com/37876129/187062373-bfef1ce9-72f8-4d6f-befc-ca03a271c19a.png)
   
   
   ### Example codes for reproduce this issue (such as a github link).
   
   ```
   @Service
   public class CityService {
   
       @Autowired
       private CityRepository cityRepository;
   
       @Autowired
       private CityService2 cityService2;
   
       @Transactional(rollbackFor = Exception.class)
       public void test(){
           City city=new City();
           city.setName("眉山");
           city.setProvince("四川");
           cityRepository.save(city);
   
           cityService2.test();
   
           List<City> all = cityRepository.findAll();
           all.forEach(x->{
               
System.out.println("cityService:"+((x.getProvince().equals("四川"))?"主库":"从库")+":"+x);
           });
       }
   }
   ```
   
   ```
   public class CityService2 {
   
       @Autowired
       private CityRepository cityRepository;
   
       @Transactional(propagation = Propagation.REQUIRES_NEW)
       public void test(){
           List<City> all = cityRepository.findAll();
           all.forEach(x->{
               
System.err.println("cityService2:"+((x.getProvince().equals("四川"))?"主库":"从库")+":"+x);
           });
       }
   }
   
   ```
   
   


-- 
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]

Reply via email to