用ssh时报错: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.
问题:只读模式下(FlushMode.NEVER/MANUAL)写操作不被允许:把你的Session改成FlushMode.COMMIT/AUTO或者清除事务定义中的readOnly标记。
解决:
这个错误是事务引起的,调用的方法不在事务中,如下:
<!-- 声明式事务管理开始 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<aop:config>
<aop:pointcut id="serviceMethods"
expression="execution(* com.klx.service.I*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="serviceMethods" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!-- 声明式事务管理结束 -->
注意这一句:execution(* com.klx.service.I*.*(..))" ,如果调用的方法不在这个包中,就会出现以上错误,把包修改一下就可以了。^_^