`
wengcang
  • 浏览: 15108 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

org.springframework.dao.InvalidDataAccessApiUsageException 异常

阅读更多
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

在使用hibernate 的 HibernateTemplate的保存方法时出现该异常,
本人经过研究与查资料找到的两种解决办法如下:

1、在调用保存方法前将flushMode改为auto

this.ht.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);


2、修改web.xml中spring的过滤器:OpenSessionInViewFilter参数如下

	<filter>
		<filter-name>OpenSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
          <init-param>  
               <param-name>flushMode</param-name>  
               <param-value>AUTO</param-value>  
           </init-param>
	</filter>
	<filter-mapping>
		<filter-name>OpenSessionInViewFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
0
4
分享到:
评论

相关推荐

    org.springframework.dao.InvalidDataAccessApiUsageException

    其中一种较为常见的异常是 `org.springframework.dao.InvalidDataAccessApiUsageException`。这类异常通常发生在使用Spring框架进行数据库操作(如增、删、改)时,特别是在采用Spring的注解式事务管理机制时。 ###...

    hibernate错误解决方案

    `org.springframework.orm.ObjectRetrievalFailureException`、`org.springframework.beans.factory.BeanCreationException` 和 `org.springframework.dao.InvalidDataAccessApiUsageException` 等。 #### 二、`org...

    Open_Session_In_View详解.doc

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker ...

    Hibernate事务管理.

    &lt;bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"&gt; &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler....

    HibernateTemplate源代码

    `HibernateTemplate`是Spring框架中的一个类,位于`org.springframework.orm.hibernate3`包下。它提供了一系列简化Hibernate数据访问操作的方法,并且能够自动将Hibernate异常转换为Spring的数据访问异常体系中的...

    Spring boot jpa 删除数据和事务管理的问题实例详解

    问题 1:如果各层都不加事务管理的话,会报错 `org.springframework.dao.InvalidDataAccessApiUsageException`。 解决方案:在各层中添加 `@Transactional` 注解,例如: ```java @Transactional public void ...

Global site tag (gtag.js) - Google Analytics