Home  >  Forum  >  Spring
Post New Query

Exception: Write operations are not allowed in read-only mode (FlushMode.MANUAL)


joined on
August 12,2015
Asked on October 08,2015
How to resolve following error. I am integrating spring with hibernate.

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.
org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)
org.springframework.orm.hibernate4.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:620)
org.springframework.orm.hibernate4.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:617)
org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:340)
org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:308)
org.springframework.orm.hibernate4.HibernateTemplate.save(HibernateTemplate.java:617)
com.concretepage.dao.UserDao.saveUserDetail(UserDao.java:13)
com.concretepage.action.ResultAction.execute(ResultAction.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:872)
ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1295)
ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:96)
com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:88)
ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1371)
ognl.ASTMethod.getValueBody(ASTMethod.java:90)
ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
ognl.SimpleNode.getValue(SimpleNode.java:258)

 
joined on
November 09,2013
Replied on October 08,2015

Check for @Transactional annotation in you DAO.
It should be 
@Transactional(readOnly = false)
joined on
December 28,2013
Replied on March 04,2017

Ensure following points in your code.

1. DAO class should annotated with 

org.springframework.transaction.annotation.Transactional
 
2. For JavaConfig using JPA

@Bean
public PlatformTransactionManager txManager(){
JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(
getEntityManagerFactoryBean().getObject());
return jpaTransactionManager;
}


3. For XML using JPA

<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactoryBean" />
</bean>

     <tx:annotation-driven transaction-manager="txManager" />

4. 2. For JavaConfig using Hibernate

@Bean
public HibernateTransactionManager hibernateTransactionManager(){
     return new HibernateTransactionManager(sessionFactory());
}

5. For XML using Hibernate

<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
</bean>

      <tx:annotation-driven transaction-manager="txManager" />

Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us