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

   ## 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.3.2-SNAPSHOT`
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   `ShardingSphere-JDBC`
   
   ### Expected behavior
   I have a simple Entity
   ```java
   @Entity
   @Table(name = "t_account")
   @NamedQuery(name = "findAll", query = "SELECT a FROM Account a")
   public class Account {
       @Id
       private int account_id;
       private int user_id;
       private String status;
   }
   ```
   
   shading config.yaml
   ```yaml
   
       t_account:
           actualDataNodes: ds_${0..1}.t_account_${0..1}
           tableStrategy:
             standard:
               shardingColumn: account_id
               shardingAlgorithmName: t-account-inline
   
      defaultDatabaseStrategy:
         standard:
           shardingColumn: user_id
           shardingAlgorithmName: database-inline
   
      shardingAlgorithms:
        database-inline:
          type: INLINE
          props:
             algorithm-expression: ds_${user_id % 2}
        t-account-inline:
           type: INLINE
           props:
             algorithm-expression: t_account_${account_id % 2}
   ```
   and select data with
   ```java
   entityManager.createNamedQuery("findAll", Account.class).getResultList();
   ```
   the result is not expacted.
   
   I turn on `sql-show` and the SQL look like
   ```
   2023-03-22 21:03:41,822 INFO  [ShardingSphere-SQL] (executor-thread-0) 
Actual SQL: ds_0 ::: select account0_.account_id as account_1_0_, 
account0_.status as status2_0_, account0_.user_id as user_id3_0_ from 
t_account_0 account0_ UNION ALL select account0_.account_id as account_1_0_, 
account0_.status as status2_0_, account0_.user_id as user_id3_0_ from 
t_account_1 account0_
   2023-03-22 21:03:41,822 INFO  [ShardingSphere-SQL] (executor-thread-0) 
Actual SQL: ds_1 ::: select account0_.account_id as account_1_0_, 
account0_.status as status2_0_, account0_.user_id as user_id3_0_ from 
t_account_0 account0_ UNION ALL select account0_.account_id as account_1_0_, 
account0_.status as status2_0_, account0_.user_id as user_id3_0_ from 
t_account_1 account0_
   ```
   It only return the data from `ds_0.t_account_0` and `ds_1.t_account_0`.
   
   ### Actual behavior
   It should return all data.
   
   ### Reason analyze (If you can)
   It seems that shardingsphere-jdbc does not route the SQL which is generated 
by JPA correctly. It should replace the second table with `UNION ALL select 
account1_.account_id as account_1_0_, account1_.status as status2_0_, 
account1_.user_id as user_id3_0_ from t_account_1 account1_`
   
   ### 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).
   


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