我们有一个在JBoss 4.2.3上运行的应用程序,使用Spring 2.5.2和Hibernate 3.2.6.ga. 这是在Linux JEE01 2.6.16.60-0.54.5-smp上运行,使用自己的用户.在另一台机器上写入Oracle 10G数据库.
我们正在使用标准视图 - >服务 - > dao分层.每个dao都使用@Repository注释.
这一切都是全天候运行而没有太多问题,但是每隔几天,有时几天,整个系统都会进入一个糟糕的状态,再也无法将任何内容写入数据库.这些堆栈跟踪显示在日志中:
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not
allowed in read-only mode (FlushMode.NEVER/MANUAL):
Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction
definition.
Run Code Online (Sandbox Code Playgroud)
我们扫描了整个系统,系统中有一个位置,其中flushmode临时设置为MANUAL,之后finally块将其设置回原始值.这是因为我们不希望在运行此查询之前将状态刷新到数据库.所以我们不能轻易改变这一点.普通的FlushMode设置为AUTO,在几个地方我们暂时将其设置为COMMIT并再次将其切换回默认值.
只有服务器重新启动才能将系统恢复到正常工作状态.
问题是:为什么系统将所有事务设置为只读/手动刷新模式?我用Google搜索了这个,但找不到解决方法.
这是我们的spring和hibernate配置(仅显示相关部分):
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="datasourceName" />
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="hibernateInterceptor"
class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<tx:advice id="txAdvice" transaction-manager="txManager" >
<!-- the transactional semantics... -->
<tx:attributes >
<!-- all methods …Run Code Online (Sandbox Code Playgroud)