AI1186780944 commented on issue #8934:
URL: https://github.com/apache/shardingsphere/issues/8934#issuecomment-772350379


   @xuup This problem should have nothing to do with sharding not working.It 
causes the transaction not to take effect.The scenarios I use are read-write 
separation and data desensitization.I just see that your example has the same 
problem as mine. Let's ask if you have solved it.And I have solved some of the 
above problems. The container injection of transaction manager is completed.The 
results are as follows:
   `Creating a new SqlSession
   Registering transaction synchronization for SqlSession 
[org.apache.ibatis.session.defaults.DefaultSqlSession@70f29b72]
   2021-02-03 16:32:15.247  INFO [trading-order-extend,,,] 9800 --- [    Test 
worker] ShardingSphere-SQL                       : Logic SQL: SELECT count(id) 
FROM order_service_obj
   2021-02-03 16:32:15.247  INFO [trading-order-extend,,,] 9800 --- [    Test 
worker] ShardingSphere-SQL                       : SQLStatement: 
MySQLSelectStatement(limit=Optional.empty, lock=Optional.empty)
   2021-02-03 16:32:15.248  INFO [trading-order-extend,,,] 9800 --- [    Test 
worker] ShardingSphere-SQL                       : Actual SQL: replica-ds ::: 
SELECT count(id) FROM order_service_obj
   Releasing transactional SqlSession 
[org.apache.ibatis.session.defaults.DefaultSqlSession@70f29b72]
   Transaction synchronization committing SqlSession 
[org.apache.ibatis.session.defaults.DefaultSqlSession@70f29b72]
   Transaction synchronization deregistering SqlSession 
[org.apache.ibatis.session.defaults.DefaultSqlSession@70f29b72]
   Transaction synchronization closing SqlSession 
[org.apache.ibatis.session.defaults.DefaultSqlSession@70f29b72]`。I hope it can 
help you to solve our common problems.
   My solution is as follows:
   `private SpringManagedTransactionFactory getTransactionFactory(DataSource 
dataSource) {
           SpringManagedTransactionFactory transactionFactory = new 
SpringManagedTransactionFactory();
           transactionFactory.newTransaction(dataSource, 
TransactionIsolationLevel.REPEATABLE_READ,true);
           return transactionFactory;
       }`
   The transaction manager generated by method ‘getTransactionFactory’ will be 
assigned to the properties of the mybatissqlsessionfactorybean object.This 
operation can solve the "JDBC Connection 
[org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection@41f00c4b]
 will not be managed by Spring" problem.
   And @ transactional (rollback for) to the implementation class of the 
service= Exception.class )It can solve the “SqlSession 
[org.apache.ibatis.session.defaults.DefaultSqlSession@6049f52d] was not 
registered for synchronization because synchronization is not active” problem。
   But I don't know why it keeps creating and destroying sqlsessions when 
executing SQL.It may be related to multiple data sources. Maybe so. Hope to get 
the author's solution.


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