title: Getting error "Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition"
body: <p>I'm getting the error:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p><strong>LoginController.java</strong></p>
  
  <pre><code>@Controller
  
  public class LoginController {
  
  @Autowired
  
  private RegisterDao dao;
  
  @RequestMapping(value = "registerpage", method = RequestMethod.GET)
  
  public ModelAndView getRegisterPage() {
  
      System.out.println("control is in getRegister method");
  
      return new ModelAndView("register", "reg", new Register());
  }
  
  
  @RequestMapping(value = "registeruser", method = RequestMethod.POST)
  public ModelAndView registerUser(HttpServletRequest request) {
  
      System.out.println("control is in registeruser method");
  
      Register register = new Register();
  
      register.setUname(request.getParameter("uname"));
      register.setPassword(request.getParameter("password"));
      register.setEmail(request.getParameter("email"));
      register.setDob(request.getParameter("dob"));
      register.setAge(request.getParameter("age"));
      register.setCountry(request.getParameter("country"));
  
  
  
      dao.addUser(register);
  
      return new ModelAndView("success");
  }
  
  @RequestMapping(value = "delete", method = RequestMethod.GET)
  public ModelAndView delete() {
  
      return new ModelAndView("delete");
  }
  
  @RequestMapping(value = "deleteUser", method = RequestMethod.DELETE)
  
  public void deleteUser(@RequestParam("uname") String uname, ModelMap map) {
  
      Register register = new Register();
      register.setUname(uname);
      dao.deleteUser(register);
  
  }
  
  @RequestMapping(value = "readUsers", method = RequestMethod.GET)
  
  public List&lt;Register&gt; usersList(ModelMap map) {
  
      List&lt;Register&gt; register = dao.readUsers();
  
      map.addAttribute("Users", register);
  
      return register;
  }
  }
  </code></pre>
  
  <p><strong>Register.java</strong></p>
  
  <pre><code>`package com.spring.dao;
  
  import java.util.List;
  
  import com.spring.model.Register;
  
  public interface RegisterDao {
  public void addUser(Register register);
  
  public List&lt;Register&gt; readUsers();
  
  public void deleteUser(Register register);
  
  }
  </code></pre>
  
  <p>Spring-servlet.xml</p>
  
  <pre><code>&lt;context:component-scan base-package="com.spring" /&gt;
  
  &lt;mvc:annotation-driven /&gt;
  
  &lt;tx:annotation-driven /&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  &lt;bean id="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"&gt;&lt;/bean&gt;
  
  &lt;bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="template" class="org.springframework.orm.hibernate5.HibernateTemplate"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
      id="sessionFactory"&gt;
      &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;com.spring.model.Register&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
  
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;
      &lt;property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" /&gt;
      &lt;property name="username" value="scott" /&gt;
      &lt;property name="password" value="tiger" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>@Service
  public class RegisterDaoImpl implements RegisterDao {
  
  @Autowired
  
  private HibernateTemplate template;
  
  public void addUser(Register register,HttpServletRequest request,HttpServletResponse response) {
      // TODO Auto-generated method stub
  
      System.out.println("control is in adduser method of daoimpl");
  
  
      template.saveOrUpdate(register);
  
  }
  
  public List&lt;Register&gt; readUsers() {
      // TODO Auto-generated method stub
  
      System.out.println("control is in readuser method of daoimpl");
  
      List&lt;Register&gt; list = template.loadAll(Register.class);
      return list;
  }
  
  public void deleteUser(Register register) {
      // TODO Auto-generated method stub
  
      System.out.println("control is in deleteuser method of daoimpl");
  
      template.delete(register);
  
  }
  
  public void addUser(Register register) {
      // TODO Auto-generated method stub
  
      template.save(register);
  
  }
  }
  
  pom.xml 
  </code></pre>
  
  <p>http://maven.apache.org/xsd/maven-4.0.0.xsd">
      4.0.0</p>
  
  <pre><code>&lt;groupId&gt;com.spring&lt;/groupId&gt;
  &lt;artifactId&gt;RegistrationWithSpringMvc&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
  &lt;name&gt;RegistrationWithSpringMvc&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
  
  &lt;dependencies&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;4.3.2.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-web --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;version&gt;4.3.2.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/com.hynnet/oracle-driver-ojdbc6 --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;ojdbc6&lt;/artifactId&gt;
          &lt;version&gt;11.2.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-orm --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;4.3.2.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;4.3.2.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;5.2.4.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.2.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/javax.servlet/jstl --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
      &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
      &lt;version&gt;1.7.21&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.jboss.logging&lt;/groupId&gt;
      &lt;artifactId&gt;jboss-logging&lt;/artifactId&gt;
      &lt;version&gt;3.3.0.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.0.2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.5&lt;/source&gt;
                  &lt;target&gt;1.5&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>