title: Spring MVC 3.0.x file upload - Why isn't the original model returned?
body: <p>I am using Springs MVC 3.0.x to upload a csv file. After reading <a href="http://www.ioncannon.net/programming/975/spring-3-file-upload-example/" rel="nofollow">Carson McDonald's article</a> I found it pretty straight forward to upload a file. In his example, he calls his model <code>UploadItem</code>. My model is called <code>CsvFile</code> which is just a POJO.</p>
  
  <p>I wanted to enhance the model to contain the data source as well. So, I defined the data source bean in xml and instaniate it when the GET method is called. The object had hash code 3fa980b. The constructor which takes a data source was called as expected when the spring bean configuration file is loaded. I then add it to the org.springframework.ui.Model. </p>
  
  <pre><code>@RequestMapping( method = RequestMethod.GET)
  public String getUploadForm(Locale locale, Model model) {
      ApplicationContext context = new ClassPathXmlApplicationContext("observation-service.xml");
      CsvFile csvFile = (CsvFile)context.getBean("csvfile");
      logger.info("csvfile in get " + csvFile.toString() );
      model.addAttribute("csvFile",csvFile);
      return "npnSubmitData";
  }
  </code></pre>
  
  <p>The next step got me by surprise. When the POST handler is being called the default constructor for the CsvFile is called. This provides access to a CsvFile object but it is different with hash code 53b5168d and data source is null. I expected the same object to be returned. </p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public String create(CsvFile csvFile, BindingResult result) {
      logger.info("upload file. " + csvFile.toString());
      if (result.hasErrors()) {
          return "npnSubmitData";
      }
      return "populated";
  }
  </code></pre>
  
  <p>Why isn't the original object returned? </p>