gpt4 book ai didi

java - 如果没有配置交易会出现异常吗?

转载 作者:行者123 更新时间:2023-12-02 07:43:23 25 4
gpt4 key购买 nike

我正在使用 spring/hibernate 独立应用程序。如果我不配置交易,我将低于预期。

Exception in thread "Thread-1" org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

在spring/hibernate集成应用中是否必须有事务配置?

谢谢!

最佳答案

基本上是的。 Hibernate documentation说:

Database, or system, transaction boundaries are always necessary. No communication with the database can occur outside of a database transaction (this seems to confuse many developers who are used to the auto-commit mode). Always use clear transaction boundaries, even for read-only operations. Depending on your isolation level and database capabilities this might not be required, but there is no downside if you always demarcate transactions explicitly. Certainly, a single database transaction is going to perform better than many small transactions, even for reading data.

关于java - 如果没有配置交易会出现异常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11272260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com