【发布时间】:2011-02-09 01:03:33
【问题描述】:
在一些特定的请求后,我的应用程序被冻结了,这让我很痛苦。 调试表明代码在调用 Spring bean(单例)方法的行上没有任何堆栈跟踪或线程终止:
myDaoService.getUserById(id)
我猜它正在中断,而不是冻结,因为分析器显示同一线程正在尝试处理后续请求。
无法追踪是什么原因造成的。
幸运的是我发现了原因:我在事务范围之外调用了其中一个 DAO 方法,但它以只读模式访问它。
现在,问题:
Do you have any clue why wasn't that traceable by debugger?
Why a method accessing db in read-only mode out of transaction caused such behavior?
Is there a way to completely forbid querying out of transaction scope?
无论我做错了什么,我真的很害怕在响应我的错误操作时没有抛出任何异常或任何其他错误输出!
我的休眠配置:
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.connection.pool_size">32</property>
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.1.1/db_test</property>
<property name="hibernate.connection.password">xxxxxx</property>
<property name="hibernate.connection.username">xxxxxx</property>
春季版是3.0
休眠版本是 3.6
Tx Manager 是 org.springframework.orm.hibernate3.HibernateTransactionManager
【问题讨论】:
-
那么,您为解决问题所做的只是将@Transactional 注解添加到您的DAO 方法中?
-
@Luciano Fiandesio,是的)