spring配置hibernate抛出read only 异常

来源:互联网 发布:百度大数据产品 编辑:程序博客网 时间:2024/06/06 18:31

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 

根据异常提示可以判断,“只读”,说明当前方法并没有写入和修改的权限,
debug调试的时候会抛出反射包 java.lang.reflec下的InvocationTargetException 异常,这个异常会
误导,其次这个异常涉及的太广泛,不易查找错误

解决办法:
需要在spring的配置文件中将事物只读设置为false或者涉及的方法定为"PROPAGATION_SUPPORTS"。
如下:

<tx:method name="涉及方法" read-only="false"/> 
或者
<property name="transactionAttributes">
<props>
<prop key="涉及方法">PROPAGATION_SUPPORTS</prop>
</props>
</property>

0 0
原创粉丝点击