Announcement Announcement Module
Collapse
No announcement yet.
Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL) 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/MANUAL)

    I am getting the following exception:
    Method execution failed:
    org.springframework.dao.InvalidDataAccessApiUsageE xception: 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 definition.
    at org.springframework.orm.hibernate3.HibernateTempla te.checkWriteOperationAllowed(HibernateTemplate.ja va:1085)
    I have standard Hibernate 3 wiring to my DAO layer and 'service' layer and everything was working fine until I added a MethodInterceptor that intercepts before my 'save*' methods to a few of my DAOs so that I can do some work before the data is inserted into the database. I am suspecting that the fact there is an interceptor is causing issue... has anyone run into this type of error before and if so how did you resolve the problem.

    Thanks in advance.
    -Derrick

    BTW, the exception is thrown before the save operation meaning nothing saves to persistent storage.

  • #2
    Just annotate your service-layer methods that are writable with following tag:
    @Transactional(readOnly = false)

    You should do this in the interface.

    Comment


    • #3
      Thank you, I will read http://www.springframework.org/docs/...ansaction.html this article as well.

      Comment


      • #4
        The @Transactional annotation did not solve the problem. I will have to dig into this a bit. Any other tips are appreciated.

        Thanks
        -Derrick

        Comment


        • #5
          Can you post some details about your configuration? The message is caused since you are trying to write information through the session while inside a read-only transaction.

          Comment


          • #6
            I am geting same problem,
            my config file is
            Code:
            	<aop:spring-configured/>
            	
            	<aop:config proxy-target-class="true">
            		<aop:advisor pointcut="execution(* com.jaoso..*Controller.*(..))"
            			advice-ref="txAdvice"/>
            	</aop:config>
            	<tx:advice id="txAdvice">
            		<tx:attributes>
            			<tx:method name="*"/>
            		</tx:attributes>
            	</tx:advice>
            <!--Hibernate SessionFatory-->
            	<bean id="sessionFactory"
            		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            		<property name="dataSource">
            			<ref bean="dataSource"/>
            		</property>
            		<property name="annotatedClasses">
            			<list>
            				<value>com.jaoso.core.domain.Hello</value>
            			</list>
            		</property>
            		<property name="annotatedPackages">
            			<list>
            				<value>com.jaoso.core.domain</value>
            			</list>
            		</property>
            		<property name="hibernateProperties">
            			<props>
            				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
            				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            				<prop key="hibernate.cache.use_query_cache">
            					${hibernate.cache.use_query_cache}</prop>
            				<prop key="hibernate.cache.provider_class">
            					${hibernate.cache.provider_class}</prop>
            				<prop key="hibernate.hbm2ddl.auto">update</prop>
            			</props>
            		</property>
            	</bean>
            	
            	<!--Hibernate TransactionManager-->
            	<bean id="transactionManager"
            		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            		<property name="sessionFactory" ref="sessionFactory"/>
            	</bean>
            my domain object is
            Code:
            @MappedSuperclass
            @Configurable(autowire = Autowire.BY_NAME)
            public abstract class BaseEntity<T> extends PersistentSupport<T> {
            
            	protected Long id;
            
            	protected String description;
            
            	protected String name;
            
            	public BaseEntity() {
            
            	}
            
            	@Id
            	@GeneratedValue(strategy = GenerationType.AUTO)
            	public Long getId() {
            		return id;
            	}
            
            	public void setId(Long id) {
            		this.id = id;
            	}
            
            	public String getDescription() {
            		return description;
            	}
            
            	public void setDescription(String description) {
            		this.description = description;
            	}
            
            	public String getName() {
            		return name;
            	}
            
            	public void setName(String name) {
            		this.name = name;
            	}
            
            }
            Hell domain extends baseEntity
            Code:
            @Entity
            public class Hello extends BaseEntity<Hello> {
            
            }
            when i deloyp it into tmocat and try to create a new recodr,then i get the same exception.

            Thanks
            --Tim

            Comment


            • #7
              Are you using OpenSessionInView or any read-only transaction? How do you write the new objects to the database, through the HibernateTemplate?

              Comment


              • #8
                Please ignore this posting. I was being very stupid!
                Last edited by graham.ford; Nov 16th, 2006, 10:02 AM.

                Comment


                • #9
                  Waht was the mistake that you committed?

                  Hi Graham,

                  I understand that you were able to find the solution for the problem you mentioned in this thread. Can you please let me know the solution? I am also getting the same error but still unable to resolve it. The following is snippet of my log file:

                  org.springframework.dao.InvalidDataAccessApiUsageE xception: 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 definition.

                  Thanks
                  Raj

                  Comment


                  • #10
                    Originally posted by rajvis16 View Post
                    Hi Graham,

                    I understand that you were able to find the solution for the problem you mentioned in this thread. Can you please let me know the solution? I am also getting the same error but still unable to resolve it. The following is snippet of my log file:

                    org.springframework.dao.InvalidDataAccessApiUsageE xception: 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 definition.

                    Thanks
                    Raj
                    Were you able to solve it? I'm having the same problem in my application.

                    Comment


                    • #11
                      I had it resolved

                      In the applicationContext.xml I had the following snippet:

                      <tx:advice id="txAdvice1">
                      <tx:attributes>
                      <tx:method name="saveOrUpdate*" propagation="REQUIRED"/>
                      <tx:method name="save*" propagation="REQUIRED"/>
                      <tx:method name="insertObject*" propagation="REQUIRED"/>
                      <tx:method name="update*" propagation="REQUIRED"/>
                      <tx:method name="*" propagation="NEVER" read-only="true"/>
                      </tx:attributes>
                      </tx:advice>

                      <aop:config>
                      <aop:advisor pointcut="execution(* *..TestFacadeImpl.*(..))" advice-ref="txAdvice1"/>
                      </aop:config>
                      I don't know the intention of why it was done in that way (Actually it was some third party vendor from whom we got the code).

                      I had written some new method whose name didn't start with any of the above method name and hence I was getting the error.

                      So when I created my own advice as below I got rid of that error:

                      <tx:advice id="txAdvice2">
                      <tx:attributes>
                      <tx:method name="insertObject*"/>
                      <tx:method name="updateObject*"/>
                      <tx:method name="*" read-only="true"/>
                      </tx:attributes>
                      </tx:advice>
                      <aop:config>
                      <aop:advisor pointcut="execution(* *..AbstractDAOFacilitator.*(..))" advice-ref="txAdvice2"/>
                      </aop:config>
                      I hope it helps.

                      Comment

                      Working...
                      X