Skip to content

Commit cd503af

Browse files
committed
docs: Fix SqlSession direct API usage caveats based on actual behavior(#531)
This commit updates the documentation for the direct use of the raw MyBatis SqlSession API, resolving the long-standing discrepancy reported in #531. The previous documentation incorrectly stated that using SqlSession.openSession() within a Spring transaction would "throw an exception" and "not participate in any Spring transactions." The revised documentation reflects the actual behavior.
1 parent 65cc15a commit cd503af

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/site/markdown/using-api.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ public class UserDaoImpl implements UserDao {
2121
}
2222
```
2323

24-
Use this option <strong>with care</strong> because wrong usage may produce runtime errors or worse, data integrity problems. Be aware of the following caveats with direct API usage:
24+
Use this option **with care** because wrong usage may produce runtime errors or worse, data integrity problems. Be aware of the following caveats with direct API usage:
2525

26-
* It will **not** participate in any Spring transactions.
27-
* If the `SqlSession` is using a `DataSource` that is also being used by a Spring transaction manager and there is currently a transaction in progress, this code **will** throw an exception.
26+
* Unless **explicitly managed by Spring's `@Transactional` annotation** or configured for **auto-commit** at the database connection level, the raw `SqlSession` does **not** participate in any transaction management. Reliance on the raw `SqlSession` is highly discouraged as it bypasses Spring's automatic resource management mechanism.
2827
* MyBatis' `DefaultSqlSession` is not thread safe. If you inject it in your beans you **will** get errors.
2928
* Mappers created using `DefaultSqlSession` are not thread safe either. If you inject them it in your beans you **will** get errors.
30-
* You must make sure that your `SqlSession`s are **always** closed in a finally block.
29+
* You must make sure that your `SqlSession`s are **always** closed in a finally block.

0 commit comments

Comments
 (0)