xuup commented on issue #8934:
URL: https://github.com/apache/shardingsphere/issues/8934#issuecomment-759151018
#### Explain the problem further
I use mybatis + sharding-jdbc to achieve sharding and replica. The
application file is the same as above.
Sharding logic and read-write separation logic is:
sharding:
user_id % 2 ==0 ---> ds_0
user_id % 2 ==1 ---> ds_1
replica:
insert : primary_ds_0 primary_ds_1
read: primary_ds_0_replica_0, primary_ds_0_replica_1,
primary_ds_1_replica_0, primary_ds_1_replica_1
```xml
spring.shardingsphere.rules.replica-query.data-sources.ds_0.primary-data-source-name=primary_ds_0
spring.shardingsphere.rules.replica-query.data-sources.ds_0.replica-data-source-names=primary_ds_0_replica_0,
primary_ds_0_replica_1
spring.shardingsphere.rules.replica-query.data-sources.ds_1.primary-data-source-name=primary_ds_1
spring.shardingsphere.rules.replica-query.data-sources.ds_1.replica-data-source-names=primary_ds_1_replica_0,
primary_ds_1_replica_1
```
I execute test case, condition column is user_id and user_id=2, sql should
be route ds_0, and read in primary_ds_0_replica_0 or primary_ds_0_replica_1.
```java
@Test
public void selectByCondition(){
Order order = new Order();
order.setUserId(2); //ds0
List<Order> lst = orderDao.selectByCondition(order);
System.out.println("hello" + lst.size());
}
```
but in fact , there are two results from ds_0 and ds_1 like this
```java
JDBC Connection
[org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection@72b6832e]
will not be managed by Spring
==> Preparing: SELECT * FROM t_order where user_id = ?;
==> Parameters: 2(Integer)
<== Columns: order_id, user_id, address_id, status
<== Row: 553170939157131264, 2, 2, INSERT_TEST_ds0
<== Row: 553170939157131264, 2, 2, INSERT_TEST_ds1
<== Total: 2
Closing non transactional SqlSession
[org.apache.ibatis.session.defaults.DefaultSqlSession@4337afd]
```
After my verification,replica function is work , it can read from primary
database and read from replica databases, but sharding cannot work normal, it
shoule be route to ds_0 but be routed to ds_0 and ds_1.
pom.xml
```xml
<shardingsphere.version>5.0.0-alpha</shardingsphere.version>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
```
case git: https://github.com/xuup/mybatis-sharding.git (master)
----------------------------------------------------------------
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:
[email protected]