我整合  ssh2  (applicationContext-actions.xml,applicationContext-beans.xml,applicationContext-common.xml)
在添加时出现如下异常  可不知道到底哪里
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.

解决方案 »

  1.   

    在用openSessionInView时,如果采用默认的事务管理(就是在spring配置文件里没有配置事务管理),在调用HibernateDaoSupport类里的getHibernateTemplate()里的增删改方法时,会抛出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' er from transaction definition.这个错.
    第一次看到这个错,肯定会觉得纳闷,它要你修改session的模式,或者移除readOnly er.但是你从来都没有设置session的模式.
    原因:spring2.0里面的OpenSessionInViewFilter的getSession方法中会对session的flushMode设定一个默认为NEVER的值,而这个值在hibernate3.0似乎是不能理解的.
      

  2.   

    解决办法:在spring配置文件里配置自己的事务,
    <bean>
       <property ref="sessionFactory" />
    </bean><tx:advice >
       <tx:attributes>
        <tx:method propagation="REQUIRED" />
        <tx:method propagation="REQUIRED" />
        <tx:method read-only="true" />
       </tx:attributes>
    </tx:advice>
    <aop:config>
       <aop:advisor pointcut="execution(* cn.xg.service.impl.*.*(..))"
        advice-ref="txAdvice" />
    </aop:config>
    另外你也可以重写OpenSessionInView这个Filter类的getSession方法,加一句this.setFlashMode(FlashMode.AUTO)
      

  3.   

    这是因为你没有给你添加方法事物管理。。
    把你的配置改一下。                <tx:attributes>
    <tx:method name="save*" propagation="REQUIRED"/>
    <tx:method name="update*" propagation="REQUIRED"/>
    <tx:method name="delete*" propagation="REQUIRED"/>
    <tx:method name="*" read-only="true"/>
    </tx:attributes>
    上面是一中配置方法,你也可以                <tx:attributes>
    <tx:method name="get*" read-only="true"/>
                            <tx:method name="query*" read-only="true"/>
                            <tx:method name="delete*" propagation="REQUIRED"/>
    </tx:attributes>但是你的方法的命名要规范点。。
      

  4.   

     <tx:method name="delete*" propagation="REQUIRED"/>
    上面第2段配置这句改下
     <tx:method name="*" propagation="REQUIRED"/>
    实在不好意思。。