我的spring配置文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
   
   <import resource="applicationContext-km.xml"/> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.rickey..*.*Dao.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.rickey..*.*DaoImpl.*(..))" />
</aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
<tx:method name="*update*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
<tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
<tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice></beans>调用方法:this.getHibernateTemplate().save(实体)时,发生以下异常:
Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' er from transaction definition. 
我想应该是spring的配置文件有误造成,但不知道问题在哪里,望各位帮忙解决一下!

解决方案 »

  1.   

    检查你的方法名
    http://topic.csdn.net/u/20080605/23/d336d826-39d4-475c-b460-f4ff01f676b1.html
      

  2.   

    http://byduke.javaeye.com/blog/179045
      

  3.   

    我在dao中的方法名为:addRickry(Rickry rickry )这也有问题??
      

  4.   

    我在dao中的方法名为:addRickry(Rickry rickry ) 这也有问题??
      

  5.   

    报错很明显啊,告诉你怎么改了啊。  <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
                <tx:method name="*update*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
                <tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
                <tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
                <tx:method name="*" read-only="true" />
            </tx:attributes>
        </tx:advice>
    把 read-only 改为 false试试。
      

  6.   

    Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' er from transaction definition. 
    写操作不能使用,使用read-only 模式。
    在程序里面设置
    hibernateTemplate.setFlushMode(FlushMode.COMMIT);
      

  7.   

    当然有问题了,你增加的话肯定是进行事务操作了。但是被你设置成readonly了,你还是修改成save吧
      

  8.   

    <!-- 事务配置 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <!-- 查询方法只读 -->
    <tx:method name="find*" propagation="REQUIRED" read-only="true"/>
    <!-- 其它方法使用普通事务 -->
    <tx:method name="insert*" propagation="REQUIRED" />
    <tx:method name="delete*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    </tx:attributes>
    </tx:advice>只有查询方法才是只读