org.springframework.dao.InvalidDataAccessApiUsageException错误

  今天调试BUG时调到使用HibernateTemplate的saveOrUpdate方法时,遇到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.

  网上查找的资料对该问题的解释如下:

  问题原因分析:

  为了解决session closed 错误而是用 openSessionInViewInterceptor 或者 openSessionInViewFilter 延迟加载的错误,但是在我们开启OpenSessionInViewFilter这个过滤器的时候FlushMode就已经被默认设置为了MANUAL, 如果FlushMode是MANUAL或NEVEL,在操作过程中 hibernate会将事务设置为readonly,所以在增加、删除或修改操作过程中会出现如下错误

  摘自:http://www.tuicool.com/articles/N3QzMb

  另外查找到的解决方法是将FlushMode改AUTO,再调用saveOrUpdate()方法,目前这样就可以执行通过,示例如下:

  

1 this.hibernateTemplate.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
2 this.hibernateTemplate.saveOrUpdate(unreadEvent);
时间: 2024-10-08 23:04:21

org.springframework.dao.InvalidDataAccessApiUsageException错误的相关文章

hibernate框架学习错误集锦-org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL)

最近学习ssh框架,总是出现这问题,后查证是没有开启事务. 如果采用注解方式,直接在业务层加@Transactional 并引入import org.springframework.transaction.annotation.Transactional; 详细信息,可以参考下面博客: 参考资料:http://blog.csdn.net/longxia1987/article/details/7819242 org.springframework.dao.InvalidDataAccessApi

org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: sys.entity.Role; nested exception is org.hibernate.PersistentObjectException: 的解决方案

1.错误信息 org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: sys.entity.Role; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: sys.entity.Role at org.springframew

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integer (n/a)];

题记:以前记录过一些自己遇到的BUG,这个行为,让我一看报错的提示信息就能定位到问题的所在,后来记得比较多了,好多是重复性的再加上比较忙就没有详细的记录了,今天的工作量比较小,就顺便记录一下,以便以后更快的解决此类问题. BUG的报错信息如下所示: org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integ

Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity解决方法

1.错误信息 Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity 2.错误原因 因为试图给 某一个new 的Transient对象 的某一个属性赋一个 已经Persistent 对象或者Detached 对象值.导致最后save 或者merge 这个

org.springframework.dao.InvalidDataAccessApiUsageException

在执行service中一个方法bumenAuth()时出现错误: 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 from transaction def

OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException

本文转载:Iuranus 报错: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 definit

org.springframework.dao.InvalidDataAccessApiUsageException: The given object has a null identifier:

JSP 页面保存操作报错: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- exception org.springframework.dao.InvalidData

org.springframework.dao.InvalidDataAccessApiUsageException报错

2018-01-09 18:12:29,980 [qtp1501019626-21] ERROR - 外部接口调用方法[TestController$$EnhancerBySpringCGLIB$$825c015b.testDemo6]异常:org.springframework.dao.InvalidDataAccessApiUsageException: No EntityManager with actual transaction available for current thread

jpa语句报 org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that position [2] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that position

@Query("SELECT area from Area AS area WHERE area.state=0 AND area.name like %?1% ")Area findByIsCityAndNameLike(int iscity,String name); 第一反应: 将 AND area.name like %?1% 后的 1要改成2 但是依然报错仔细反应了 @Query("SELECT area from Area AS area WHERE area.s