linghengqian commented on issue #30242: URL: https://github.com/apache/shardingsphere/issues/30242#issuecomment-1960747665
- You can see an example of manual operation at https://github.com/linghengqian/shardingsphere-seata-spring-boot-test/blob/master/src/main/java/com/lingh/shardingsphereseataspringboottest/commons/repository/AddressRepository.java#L130 . `t_table_does_not_exist` is a table that does not exist at all. ```java Connection connection = dataSource.getConnection(); try { connection.setAutoCommit(false); connection.createStatement().executeUpdate("INSERT INTO t_address (address_id, address_name) VALUES (2024, 'address_test_2024')"); connection.createStatement().executeUpdate("INSERT INTO t_table_does_not_exist (test_id_does_not_exist) VALUES (2024)"); connection.commit(); } catch (SQLException e) { connection.rollback(); } finally { connection.setAutoCommit(true); connection.close(); } try ( Connection conn = dataSource.getConnection(); ResultSet resultSet = conn.createStatement().executeQuery("SELECT * FROM t_address WHERE address_id = 2024")) { assertThat(resultSet.next(), is(false)); } ``` - In fact, it is not limited to this operation, refer to https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/special-api/transaction/seata/#usage-restrictions . - When operating ShardingSphere data sources, you need to operate real distributed transactions just like local transactions. Long story short, you should not use the Seata Java API when using ShardingSphere’s Seata integration. > 1. Manually obtain the `java.sql.Connection` instance created from the ShardingSphere data source, and manually calling the `setAutoCommit()`, `commit()` and `rollback()` methods is allowed. > 2. Using the Jakarta EE 8 `javax.transaction.Transactional` annotation on the function is allowed. > 3. Using Jakarta EE 9/10’s `jakarta.transaction.Transactional` annotation on functions is allowed. > 4. Using Spring Framework’s `org.springframework.transaction.annotation.Transactional` annotation on functions is allowed. > 5. Using the `io.seata.spring.annotation.GlobalTransactional` annotation on the function is **not** allowed. > 6. Manually create `io.seata.tm.api.GlobalTransaction` instance from `io.seata.tm.api.GlobalTransactionContext`, calling the `begin()`, `commit()` and `rollback()` methods of an io.seata.tm.api.GlobalTransaction instance is **not** allowed. - These limitations originally came from the handling on the Seata side. -- 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]
