Announcement Announcement Module
Collapse
No announcement yet.
readOnly error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • readOnly error

    Hi guys, I'm getting a nullpointerexception from this warning:
    Code:
    WARN - DispatcherServlet.doService(609) | Handler execution resulted in exception - forwarding to resolved error view
    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO respectively remove 'readOnly' marker from transaction definition
    Here's the code I'm trying to call:

    Code:
        public void setRead(String id){
        	Long msgId = Long.valueOf(id);
        	Message message = (Message) getHibernateTemplate().get(Message.class, msgId);
        	if(!message.isRead()){
        		message.setRead(true);
        		getHibernateTemplate().saveOrUpdate(message);
        	}
        }
    I have other code that calls saveOrUpdate without any problems, but I didn't do a get before those. The warning is pretty descriptive, but I was hoping somebody might be able to shed a little light on why the function is in read-only mode?

    Thanks

  • #2
    Are you using any transaction demarcation for method setRead? You should use a transaction attribut that support write opérations.
    HTH

    Comment


    • #3
      Code from MessageController:
      Code:
      public class MessageController implements Controller {
          private final Log log = LogFactory.getLog(MessageController.class);
          private MessageManager messageManager = null;
          
          public void setMessageManager(MessageManager messageManager) {
              this.messageManager = messageManager;
          }
              
          public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
          															throws Exception {
          	
          	String msgId = request.getParameter("id");
          	messageManager.setRead(msgId);
          	
          	return new ModelAndView("WEB-INF/user/message.jsp","msg",
          							messageManager.getMessage(msgId));
          }
      }

      Beans in applicationContext
      Code:
      <bean id="messageController" class="org.appfuse.web.MessageController">
      		<property name="messageManager"><ref bean="messageManager"/></property>
      	</bean>
      
          <bean id="txProxyTemplate" abstract="true"
              class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
              <property name="transactionManager"><ref bean="transactionManager"/></property>
              <property name="transactionAttributes">
                  <props>
                      <prop key="save*">PROPAGATION_REQUIRED</prop>
                      <prop key="remove*">PROPAGATION_REQUIRED</prop>
                      <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
                  </props>
              </property>
          </bean>
      
      	<bean id="messageManager" parent="txProxyTemplate">
              <property name="target">
                  <bean class="org.appfuse.service.impl.MessageManagerImpl">
                      <property name="messageDAO"><ref bean="messageDAO"/></property>
                  </bean>
              </property>
          </bean>
      
      	<bean id="messageDAO" class="org.appfuse.dao.hibernate.MessageDAOHibernate">
              <property name="sessionFactory"><ref local="sessionFactory"/></property>
          </bean>
      This is the same sort of code I've used in other places, so I'm not sure what I'm doing wrong.

      Comment


      • #4
        I can see that method setRead does save data into the database but is marked readOnly:
        Code:
        <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
        Please add this line to your transactionAttributes:
        Code:
        <prop key="set*">PROPAGATION_REQUIRED</prop>
        HTH

        Comment


        • #5
          ah, I see now, thanks a bunch!

          Comment

          Working...
          X