Results 1 to 3 of 3

Thread: Transactions hibernate: read-only mode &

  1. #1
    Join Date
    Oct 2007
    Posts
    2

    Default Transactions hibernate: read-only mode &

    Hello,
    I am trying to setup spring-hibernate-jsf and I keep getting an exception that prevents me from moving further. 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. My connection to db is working as I can do a select but I cannot update!
    I have searched around the forum but could not find a clear solution for this, although the problem has appeared to others before. This is how I have configured my applicationContext.xml and I attach the exception below. I have tried different variations to solve this
    Could someone give me a suggestion on what to do?
    Thank you
    Rigas

    <beans>
    <bean id="baseTransactionProxy"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean"
    abstract="true">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>
    <bean id="userProxy" parent="baseTransactionProxy">
    <property name="target" ref="userManager" />
    <property name="transactionAttributes">
    <props>
    <prop key="saveUser">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>
    <bean id="userManager"
    class="UserServiceManagerImpl">
    <property name="userDao" ref="userDao"/>
    </bean>
    <bean id="lobHandler" class="org.springframework.jdbc.support.lob.Defaul tLobHandler"
    lazy-init="false" />

    <!-- Database Connection: Can be done with a jndi name or by specifying connection properties -->
    <!--
    <bean id="printtoolDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName"><value>java:comp/env/jdbc/printtoolDataSource</value></property>

    </bean>
    -->
    <bean id="printtoolDataSource"
    class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    </bean>

    <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->

    <bean id="printtoolHibernateProperties"
    class="org.springframework.beans.factory.config.Pr opertiesFactoryBean">
    <property name="properties">
    <props>
    <prop key="hibernate.connection.autocommit">true</prop>
    <prop key="org.hibernate.SQL">debug</prop>
    <prop key="org.hibernate.transaction">true</prop>
    <prop key="hibernate.hbm2ddl.auto">validate</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.Orac leDialect</prop>
    <prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.c3p0.minPoolSize">5</prop>
    <prop key="hibernate.c3p0.maxPoolSize">20</prop>
    <prop key="hibernate.c3p0.timeout">600</prop>
    <prop key="hibernate.c3p0.max_statement">50</prop>
    <prop key="hibernate.c3p0.testConnectionOnCheckout">fals e</prop>
    </props>
    </property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource"><ref local="printtoolDataSource" /></property>
    <property name="hibernateProperties"><ref bean="printtoolHibernateProperties" /></property>
    <property name="lobHandler"><ref local="lobHandler" /></property>
    <property name="mappingResources">
    <list>
    <value>User.hbm.xml</value>
    </list>
    </property>
    </bean>
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <bean id="userDao" class="UserDaoHibernateImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    </beans>

    public class UserDaoHibernateImpl extends HibernateDaoSupport {
    public void saveOrUpdate(User user) {
    //getHibernateTemplate().setCheckWriteOperations(fal se);
    //getHibernateTemplate().setFlushMode(HibernateTempl ate.FLUSH_AUTO);
    getHibernateTemplate().saveOrUpdate(user);
    }
    }
    public class UserServiceManagerImpl implements UserServiceManager{
    public void saveUser(UserBean user) {
    User u = new User();
    u.setUserLoginId(user.getUserLoginId());
    u.setUserName(user.getUserName());
    userDao.saveOrUpdate(u);
    }
    }

    Exception:

    [23/10/07 12:53:13:989 CEST] 0000003a WebApp E SRVE0026E: [Servlet Error]-[Faces Servlet]: javax.faces.FacesException: #{UserBean.createUser}: javax.faces.el.EvaluationException: 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 com.sun.faces.application.ActionListenerImpl.proce ssAction(ActionListenerImpl.java:79)
    at javax.faces.component.UICommand.broadcast(UIComman d.java:312)
    at javax.faces.component.UIViewRoot.broadcastEvents(U IViewRoot.java:302)

    Caused by: javax.faces.el.EvaluationException: 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 com.sun.faces.el.MethodBindingImpl.invoke(MethodBi ndingImpl.java:131)
    at com.sun.faces.application.ActionListenerImpl.proce ssAction(ActionListenerImpl.java:73)
    ... 29 more
    Caused by: 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:1095)
    at org.springframework.orm.hibernate3.HibernateTempla te$16.doInHibernate(HibernateTemplate.java:688)
    at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:372)
    at org.springframework.orm.hibernate3.HibernateTempla te.saveOrUpdate(HibernateTemplate.java:686)
    at com.upccorp.printtool.dao.hibernate.UserDaoHiberna teImpl.saveOrUpdate(UserDaoHibernateImpl.java:36)
    at com.upccorp.printtool.logic.implementation.UserSer viceManagerImpl.saveUser(UserServiceManagerImpl.ja va:36)
    at com.upccorp.printtool.faces.UserBean.createUser(Us erBean.java:61)

  2. #2
    Join Date
    Oct 2007
    Posts
    2

    Smile Found solution

    It seems it was because I was using the
    org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter
    in the web.xml

  3. #3
    Join Date
    Jul 2008
    Posts
    2

    Default More info

    So if you stopped using the OpenSessionInViewFilter, what did you use? Did you just not use a hibernateFilter?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •