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 definition

查看srping中事务管理配置:

<bean id="txProxyTemplate" abstract="true"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager">
   <ref bean="transactionManager" />
  </property>
  <property name="transactionAttributes">
   <props>
    <prop key="find*">PROPAGATION_REQUIRED</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="create*">PROPAGATION_REQUIRED</prop>
    <prop key="add*">PROPAGATION_REQUIRED</prop>
    <prop key="del*">PROPAGATION_REQUIRED</prop>
    <prop key="clear*">PROPAGATION_REQUIRED</prop>
    <prop key="build*">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>

看了之后才知道,原来的事务策略的<prop key="*">PROPAGATION_REQUIRED</prop>被删除后,bumenAuth()方法后忘了修改,所以导致报上述的错误

修改方法一:

将此方法修改为update或者build,add....等上述策略名称开头的方法:如:updateBumenAuth()

修改方法二:

增加<prop key="*">PROPAGATION_REQUIRED</prop>即可

修改方法三:

将web.xml下的

<filter>
  <filter-name>OpenSessionInViewFilter</filter-name>
  <filter-class>
   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
  </filter-class>
  <init-param>
   <param-name>singleSession</param-name>
   <param-value>true</param-value>
  </init-param>
 </filter>

中的singleSession值修改为false,即不限制整个过程用同一个session,但缺点是Hibernate Session的Instance可能会大增,使用的JDBC Connection量也会大增,如果Connection Pool的maxPoolSize设得太小,很容易就出问题

参考:关于OpenSessionView(http://liuwei1578.blog.163.com/blog/static/4958036420092104215514/)

Spring事务配置TransactionProxyFactoryBean(http://liuwei1578.blog.163.com/blog/static/49580364200921041136625/)

org.springframework.dao.InvalidDataAccessApiUsageException

时间: 2024-11-11 03:54:19

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

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: 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错误

今天调试BUG时调到使用HibernateTemplate的saveOrUpdate方法时,遇到org.springframework.dao.InvalidDataAccessApiUsageException错误: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your

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

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

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