Announcement Announcement Module
Collapse
No announcement yet.
Write operations are not allowed in read-only mode (FlushMode.NEVER) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Write operations are not allowed in read-only mode (FlushMode.NEVER)

    I use hibernate3+spring+webwork+freemarker
    but when i save data,thare are errors

    org.springframework.dao.InvalidDataAccessApiUsageE xception: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
    org.springframework.orm.hibernate3.HibernateTempla te.checkWriteOperationAllowed(HibernateTemplate.ja va:910)
    org.springframework.orm.hibernate3.HibernateTempla te$18.doInHibernate(HibernateTemplate.java:614)
    org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:312)
    org.springframework.orm.hibernate3.HibernateTempla te.saveOrUpdate(HibernateTemplate.java:612)
    hibernate.dao.HibernateDAO.saveOrUpdate(HibernateD AO.java:44)
    action.UserAction.save(UserAction.java:52)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:585)
    com.opensymphony.xwork.DefaultActionInvocation.inv okeAction(DefaultActionInvocation.java:300)
    com.opensymphony.xwork.DefaultActionInvocation.inv oke(DefaultActionInvocation.java:166)
    com.opensymphony.xwork.interceptor.AroundIntercept or.intercept(AroundInterceptor.java:35)
    com.opensymphony.xwork.DefaultActionInvocation.inv oke(DefaultActionInvocation.java:164)
    com.opensymphony.xwork.interceptor.AroundIntercept or.intercept(AroundInterceptor.java:35)
    com.opensymphony.xwork.DefaultActionInvocation.inv oke(DefaultActionInvocation.java:164)
    com.opensymphony.xwork.DefaultActionProxy.execute( DefaultActionProxy.java:116)
    com.opensymphony.webwork.dispatcher.ServletDispatc her.serviceAction(ServletDispatcher.java:272)
    com.opensymphony.webwork.dispatcher.ServletDispatc her.service(ServletDispatcher.java:237)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.doFilterInternal(OpenSessionInVie wFilter.java:172)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:73)

    applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
    <!-- Hibernate - JDBC Connection Settings -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName"><value>org.jgt.mm.mysql.Dri ver</value></property>
    <property name="url"><value>jdbc:mysql://localhost:3306/java</value></property>
    <property name="username"><value>root</value></property>
    <property name="password"><value></value></property>
    </bean>

    <!-- Hibernate Sessin Factory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource"><ref bean="dataSource"/></property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="show_sql">true</prop>
    </props>
    </property>
    <!-- Mapping files -->
    <property name="mappingResources">
    <list>
    model/User.hbm.xml
    </list>
    </property>
    </bean>

    <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator" dependency-check="none">
    <property name="proxyTargetClass">
    <value>true</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>transactionInterceptor</value>
    </list>
    </property>
    <property name="beanNames">
    <list>
    <!--<value>pessoaAction</value>-->
    </list>
    </property>
    </bean>

    <!-- Transaction Manager -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- Transaction Interceptor -->
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor .TransactionInterceptor" dependency-check="none">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="delete">PROPAGATION_REQUIRED</prop>
    <!-- default, readOnly -->
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    </beans>


    what should i do ? thanks

  • #2
    Check your UserAction bean definition.
    Maybe your save function of your UserAction class is declared as readonly.

    On the underlying jdbc api, setting the jdbc connection to readonly is a hint to the driver to enable database optimizations. The connection can still be used to do update works while I set it as readonly using oracle 9.2.0.6 jdbc driver, but exception thrown when I tested it using mysql jdbc driver(mysql-connector-java-3.1.7-bin.jar). Maybe the difference between the jdbc driver makes hibernate throws the exception when it found it is in read only mode.

    Comment

    Working...
    X