sabz90 opened a new issue #7703:
URL: https://github.com/apache/shardingsphere/issues/7703


   I am using Spring Data JPA with Hibernate (with mysql), Spring Boot 2 and SS 
4.1.1.
   Things were working fine with 4.0.0-RC1. After i updated version to 4.1.1 i 
get :-
   `
   org.apache.shardingsphere.core.exception.ShardingException: Can not update 
sharding key, logic table: [ACCOUNT_INFO], column: 
[org.apache.shardingsphere.sql.parser.sql.segment.dml.assignment.AssignmentSegment@5afa0b1a].
   `
   
   My Table ACCOUNT_INFO looks like:-
   
   - id
   - version
   - account_id  **(THIS IS THE SHARD COLUMN CONFIGURED)**
   - zip
   - name
   
   The hibernate generated sql query for update looks like :-
   
   `update ACCOUNT_INFO set name=??, account_id=??, zip=??, version=?? where id 
= ?? and version = ??
   `
   
   This statement throws the exception when executed through DAL:-
   org.apache.shardingsphere.core.exception.ShardingException: Can not update 
sharding key, logic table: [ACCOUNT_INFO], column: 
[org.apache.shardingsphere.sql.parser.sql.segment.dml.assignment.AssignmentSegment@5afa0b1a].
   
   This was not happening in 4.0.0-RC1.
   
   I debugged a bit and I found that this expects **account_id** to be present 
in the where clause. Unfortunately, Spring Data JPA does not provide a way for 
me to specify what columns will be there in where clause. I do not want to 
write custom JPA query because then version management will have to be done 
manually and also will become tedious as my table has large columns.
   
   I tried using the hint manager but it didn't work :-
   
   ```
           try(HintManager hintManager = HintManager.getInstance()) {
             hintManager
                 .addDatabaseShardingValue("ACCOUNT_INFO", 
accountEntity.getAccountId());
             hintManager.addTableShardingValue("ACCOUNT_INFO", 
accountEntity.getAccountId());
   
             session.update(accountEntity);
             transaction.commit();
           }
   ```
   
   How do i solve this ??


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


Reply via email to