解决 Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker

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标记。 

解决方法: 
web.xml配置里添加 
<filter> 
   <filter-name>OpenSessionInViewFilter</filter-name> 
   <filter-class> 
    org.springframework.orm.hibernate4.support.OpenSessionInViewFilter 
   </filter-class> 
   <init-param> 
          <param-name>sessionFactoryBeanName</param-name> 
          <param-value>sessionFactory</param-value> 
   </init-param> 
   <init-param> 
            <param-name>singleSession</param-name> 
            <param-value>true</param-value>            
   </init-param> 
   <init-param> 
           <param-name> flushMode </param-name> 
           <param-value>AUTO </param-value>         
    </init-param> 
</filter>

你可能感兴趣的:(exception)