title: Can not insert data into two tables spring mvc
body: <p>Im using Spring mvc and facing the problem about inserting data into two tables, my target is inserting data into 2 tables from 1 jsp (1 form)
  I have two 2 tables:</p>
  
  <pre><code>1.Cars
    Id
    Name
    CityId(FK) 
  
  2.City
    Id
    Name
  </code></pre>
  
  <p>this is my controller:</p>
  
  <pre><code>@RequestMapping(value="/CreateCar", method = RequestMethod.GET)
  public ModelAndView getCreateCarPage(ModelMap model) throws ServletException, IOException {
  
      try {
  
          Car myCar = new Car();
          City city = new City();
  
          myCar.setCity(city);
  
          model.addAttribute("city", city);
          model.addAttribute("createCar", myCar);
      }       
      catch(Exception e) {
          e.printStackTrace();
      }
  
      return new ModelAndView("testForm");
  }
  @RequestMapping(value="/CreateCar", method = RequestMethod.POST)
  public ModelAndView setCreateCarPage(ModelMap model,
                                       @ModelAttribute("createCar") Car createCar) throws SQLException, Exception {
  
      try {
  
          carService.createCar(createCar);
  
      }
      catch(Exception e) {
          e.printStackTrace();
      }
  
      return new ModelAndView("successProcess");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>JSP:</p>
  
  <pre><code>&lt;form:form modelAttribute="createCar" method="POST" commandName="createCar" action="/CreateCar" enctype="multipart/form-data"&gt;
  &lt;fieldset style="width:300px"&gt;          
      &lt;table cellspacing="0" cellpadding="0" align="center"&gt;                              
      &lt;tr&gt;            
          &lt;td&gt;
              &lt;label&gt;Name of car&lt;/label&gt;
              &lt;form:input path="name" id="name"/&gt;
          &lt;/td&gt;       
  
          &lt;td&gt;
              &lt;label&gt;Name of city&lt;/label&gt;
              &lt;form:input path="city.name" /&gt;
          &lt;/td&gt;                   
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input class="btn btn-danger" type="submit" value="Inser New" style="width:100px;" /&gt;&lt;/td&gt;          
      &lt;/tr&gt;   
      &lt;/table&gt;
  
  &lt;/fieldset&gt;
  </code></pre>
  
  <p></p>
  
  <p>With above source, it just insert name of car success but can not insert name of city</p>
  
  <p>Log massages:</p>
  
  <pre><code>SqlExceptionHelper - Column 'city_id' cannot be null
  </code></pre>
  
  <p>How can I fix this problem ? thank so much !</p>