I've just suffered a horrible time of having my application freezing after a few certain requests. Debug shown that the code was breaking without any stacktrace or thread termination on the line which calls a method of a Spring bean (singleton) :
myDaoService.getUserById(id)
I guess it was breaking, not freezing, because profiler shown that the same thread was trying to process subsequent request.
It was impossible to trace what causes that. Luckily I've discovered the reason: I was calling one of the DAO methods out of transaction scope, but it was accessing it in read-only mode.Now, the questions:
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?
Whatever I was doing wrong, I'm really scared of the fact that in response to my wrong actions I didn't get any exception thrown or any other error output!
My Hibernate config:
<property name="hibernate.dialect">org.hibernate.dialect.Postgre开发者_Go百科SQLDialect</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>
Spring version is 3.0
Hibernate version is 3.6 Tx Manager is org.springframework.orm.hibernate3.HibernateTransactionManagerDo you have any clue why wasn't that traceable by debugger?
No, but maybe taking a thread dump could tell you.
Why a method accessing db in read-only mode out of transaction caused such behavior?
I'd add a transaction context and try again. Don't assume that it's okay because it's read-only. It costs you little, since transactions are declarative. Add transaction management to all DAO methods and see if that helps.
精彩评论