我必須保留在@Transactional控制器中打開的ResultSet,以便在MessageConverter內使用。在會話工廠豆防止在事務提交時關閉ResultSet
<mvc:interceptors>
<bean class="org.springframework.orm.hibernate4.support.OpenSessionInViewInterceptor"
p:sessionFactory-ref="sessionFactory"/>
</mvc:interceptors>
:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.release_mode">on_close</prop>
....
</props>
</property>
</bean>
控制器方法中:
session.doWork((con) -> { con.setHoldability(HOLD_CURSORS_OVER_COMMIT); });
MVC攔截
然而PSQLException: This ResultSet is closed.
仍然存在。這是在日誌中有關片段在交易時控制方法的返回承諾:
TRACE o.h.e.j.i.JdbcCoordinatorImpl - Registering result set [[email protected]]
DEBUG o.h.e.t.s.AbstractTransactionImpl - committing
TRACE o.h.internal.SessionImpl - Automatically flushing session
TRACE o.h.internal.SessionImpl - before transaction completion
DEBUG o.h.e.t.i.j.JdbcTransaction - committed JDBC Connection
DEBUG o.h.e.t.i.j.JdbcTransaction - re-enabling autocommit
TRACE o.h.e.t.i.TransactionCoordinatorImpl - after transaction completion
TRACE o.h.internal.SessionImpl - after transaction completion
TRACE o.h.internal.SessionImpl - Setting flush mode to: MANUAL
DEBUG o.h.internal.SessionImpl - Disconnecting session
TRACE o.h.e.j.i.JdbcCoordinatorImpl - Releasing JDBC container resources [[email protected]]
TRACE o.h.e.j.i.JdbcCoordinatorImpl - Closing result set [[email protected]]
TRACE o.h.e.j.i.JdbcCoordinatorImpl - Closing prepared statement [select...]
DEBUG o.h.e.j.i.LogicalConnectionImpl - Releasing JDBC connection
DEBUG o.h.e.j.i.LogicalConnectionImpl - Released JDBC connection
DEBUG o.h.e.j.s.SqlExceptionHelper - could not advance using next() [n/a] org.postgresql.util.PSQLException: This ResultSet is closed.
有更多的東西,我可以做些什麼來阻止這種情況發生?
是在OSIV過濾器內部實際映射的資源?其他一切都看起來不錯 – Affe
我在攔截器配置中有 ',但沒有顯示,因爲沒有映射它通用。此外,這部分證明是可行的,因爲如果我不使用@Transactional,我得到了我的開放結果集。 –