title: Spring mvc - POST request with @ModelAttribute cause unnecessary sql queries
body: <p>I have a form with three select inputs, which are added from the db in the view. Everything is OK and the user can select for every select. The problem is that when I submit the form, the <code>@ModelAttribute</code> generates the same queries as the GET request (when these three selects are added into the view) and in the same, the select fields are empty after the POST.</p>
  
  <pre><code>@GetMapping("/road-assistance")
  public String viewPage(Model model, Locale locale) {
  
      model.addAttribute("roadAssistanceDto", roadAssistanceService.createRoadAssistanceDto(locale, null));
      return "admin/roadassistance/view";
  }
  
  
  
  @PostMapping("/road-assistance")
  public String createRoadAssistance(Model model, Locale locale,
                                     final @Valid @ModelAttribute("roadAssistanceDto") RoadAssistanceDto roadAssistanceDto,
                                     BindingResult bindingResult) {
      if (bindingResult.hasErrors()) {
          return "redirect:/";
      }
  
      return "admin/roadassistance/view";
  }
  </code></pre>
  
  <p>Why the <code>@PostMapping</code> generates the same queries and in the same time, I don't have the info in the view/model? </p>
  
  <p>the view -</p>
  
  <pre><code>&lt;div class="row card-pagging"&gt;
          &lt;div class="col-sm-2 mt-3 offset-sm-2"&gt;
              &lt;label data-th-text="#{control.panel.roadassistance.country}" 
   class="control-label"
                     for="country"&gt;Country&lt;/label&gt;
              &lt;select id="country" data-th-field="*{country}" class="form-control"&gt;
                  &lt;option data-th-each="countryList : ${roadAssistanceDto.countryList}"
                          data-th-value="${countryList.id}"
                          data-th-text="${countryList.countryI18n[#locale].name}"&gt;&lt;/option&gt;
              &lt;/select&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-3 mt-3"&gt;
              &lt;label data-th-text="#{control.panel.roadassistance.region}" class="control-label"
                     for="region"&gt;Region&lt;/label&gt;
              &lt;select data-th-field="*{region}" id="region" class="form-control"&gt;
                  &lt;option value='' data-th-text="#{control.panel.roadassistance.chooseregion}"&gt;&lt;/option&gt;
                  &lt;option data-th-each="reg : ${roadAssistanceDto.regionList}" data-th-value="${reg.id}"
                          data-th-text="${reg.regionI18n[#locale].name}"&gt;&lt;/option&gt;
              &lt;/select&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-3 mt-3"&gt;
              &lt;label data-th-text="#{control.panel.roadassistance.city}" class="control-label"
                     for="region"&gt;City&lt;/label&gt;
              &lt;select data-th-field="*{city}" id="city" class="form-control"&gt;
                  &lt;option value="" data-th-text="#{control.panel.roadassistance.chooseregion}"&gt;&lt;/option&gt;
                  &lt;option data-th-each="city : ${roadAssistanceDto.cityList}" data-th-value="${city.id}"
                          data-th-text="${city.cityI18n[#locale].name}"&gt;&lt;/option&gt;
              &lt;/select&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>And the RoadAssistanceDto -</p>
  
  <pre><code>public class RoadAssistanceDto implements Serializable {
  
  private Long id;
  
  private Country country;
  
  private Region region;
  
  private City city;
  
  private List&lt;Country&gt; countryList;
  
  private List&lt;Region&gt; regionList;
  
  private List&lt;City&gt; cityList;
  
  /* GETTERS AND SETTERS /*
  
  }
  </code></pre>
  
  <p>Hm... I think that I notice the problem.. there is something workng when I'm binding the fields in the thymeleaf... but anyway, why is generating these queries?</p>