2 littledingdang littleDingDang 于 2017.01.11 21:29 提问

Write operations are not allowed。。。

spring整合hibernate报错:
Exception in thread "main" 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.
at org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)
at org.springframework.orm.hibernate4.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:620)
at org.springframework.orm.hibernate4.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:617)
at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:340)
at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:308)
at org.springframework.orm.hibernate4.HibernateTemplate.save(HibernateTemplate.java:617)
at com.gy.dao.BooktwoDaoImpl.save(BooktwoDaoImpl.java:17)
at com.gy.service.BooktwoServiceImpl.save(BooktwoServiceImpl.java:28)
at com.gy.test.test1.main(test1.java:30)

applicationContext配置如下:
<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

<!-- <context:property-placeholder location="classpath:jdbc.properties" 
    file-encoding="utf-8" ignore-unresolvable="true" /> -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 配置数据源 -->
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName">
        <value>oracle.jdbc.OracleDriver</value>
    </property>
    <property name="url">
        <value>jdbc:oracle:thin:@localhost:1521:orcl
        </value>
    </property>
    <property name="username">
        <value>gaoya</value>
    </property>
    <property name="password">
        <value>gaoya</value>
    </property>
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean id="BooktwoDao" class="com.gy.dao.BooktwoDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>

<bean id="BooktwoService" class="com.gy.service.BooktwoServiceImpl">
    <property name="booktwoDao" ref="BooktwoDao"></property>
</bean>

<!-- 配置Hibernate事务管理器 -->
<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 配置事务异常封装 -->
<bean id="persistenceExceptionTranslationPostProcessor"
    class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

<!-- 基于数据源的事务管理器 -->
<!-- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" 
    p:dataSource-ref="dataSource" /> -->
<!-- 事务增强 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <!-- 事务属性定义 -->
    <tx:attributes>
    <!-- <tx:method name="save*"/>
    <tx:method name="update*"/>
    <tx:method name="delete*"/>
    <tx:method name="find*" read-only="true"/> -->
    <tx:method name="**" read-only="true" />  

        <tx:method name="**" propagation="REQUIRED"/>
    </tx:attributes>
</tx:advice>
<!-- 配合<tx:advice>和<aop:advisor>完成了事务切面的定义 -->
<!-- 使用强大的切点表达式是语言轻松定义目标方法 -->
<aop:config proxy-target-class="true">
    <!-- 通过aop定义事务增强切面 -->
    <!-- 引用事务增强 -->
    <!-- <aop:advisor advice-ref="txAdvice"
        pointcut="execution(* com.gy.service..*.* (..))" /> -->
        <aop:advisor advice-ref="txAdvice"
        pointcut="execution(* com.gy.。*.* (..))" />
</aop:config>


找了好久了还是没解决,网上的方法都试了也不行,希望大家帮帮忙

1个回答

baij1230
baij1230   2017.01.12 21:01
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Write operations are not allowed in read-only mode错误解决
问题。 开启OpenSessionInViewFilter来阻止延迟加载的错误的时候抛出了这个异常:org.springframework.dao.InvalidDataAccessApiUsageException错误 但是在我们开启OpenSessionInViewFilter这个过滤器的时候FlushMode就已经被默认设置为了MANUAL! 如果FlushMode是MANUAL或NEV
关于ssh里面的Write operations are not allowed in read-only mode (FlushMode.NEVER)
最近在整合ssh 的时候遇到了几个问题,首先是ssh中能查询数据但是不能保存,删除以及更新数据,而且总是报一个错误,就是Write operations are not allowed in read-only mode (FlushMode.NEVER); 百度了各种结果,要不就是在spring的xml文件中将read-only设置为false,要不就是在web.xml文件中加一个过滤器,但是统
Write operations are not allowed in read-only mode (FlushMode.MANUAL)错误解决
最近在配置 Structs, spring 和hibernate整合的问题: 开启OpenSessionInViewFilter来阻止延迟加载的错误的时候抛出了这个异常:     org.springframework.dao.InvalidDataAccessApiUsageException错误 但是在我们开启OpenSessionInViewFilter这个过滤器的时候Fl
hibernate异常:解决Hibernate的Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL):
hibernate异常:解决Hibernate的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 definitio
InvalidDataAccessApiUsageException 和 Write operations are not allowed in read-only mode 解决方法
这些天写webservice,一直在测接口,get方法都没问题,就从昨晚开始测save方法的时候出现了这个错误Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushM搜了一下,有这样一种说法 原因一: 这个异常产生的主要原因是DAO采用了Sprin
hibernate异常:Write operations are not allowed in read-only mode
hibernate异常: 解决Hibernate的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
(详解)Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session
昨天发现以前正常的功能报错了,错误日志如下: 报错日志: Hibernate: select taxtypecon0_.ID as ID62_, taxtypecon0_.TAX_TYPE_NAME as TAX2_62_, taxtypecon0_.EXPRESSIONS as EXPRESSI3_62_, taxtypecon0_.CREATE_DATE as CREATE4_62_,
解决Spring4+Hibernate4遇到的 Write operations are not allowed in read-only mode (FlushMode.MANUAL)
全部的错误stack类似: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove
异常:InvalidDataAccessApiUsageException:Write operations are not allowed in read-only mode
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 'readOnl
保存数据报错Write operations are not allowed in read-only mode (FlushMode.MANUAL)
1. 报错信息 org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'read