title: OneToMany relation with multiple properties in JSP form
body: <p>I have this model:</p>
  
  <p><strong>Order.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "`order`")
  public class Order {
      private Long id;
      @OneToMany(fetch = FetchType.EAGER, mappedBy = "order")
      private List&lt;OrderProduct&gt; orderProducts;
  
      @Override
      public int hashCode() {
          return new Long(id).hashCode();
      }
  
      @Override
      public boolean equals(Object obj) {
          if (obj == null) {
              return false;
          }
          if (!(obj instanceof Order)) {
              return false;
          }
          return this.id == ((Order) obj).getId();
      }
  
      /* getters &amp; setters */
  }
  </code></pre>
  
  <p><strong>OrderProduct.java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "order_product")
  public class OrderProduct {
      private Long id;
      private String name;
      private Long quantity;
      @ManyToOne
      @JoinColumn(name = "order_id")
      private Order order;
  
      /* getters &amp; setters */
  }
  </code></pre>
  
  <p>And this controller:</p>
  
  <p><strong>OrderController.java</strong></p>
  
  <pre><code>@Controller
  @SessionAttributes({"products"})
  public class OrderController {
      @Autowired
      private OrderService orderService;
  
      @Autowired
      private ProductService productService;
  
      @Autowired
      private SecurityService securityService;
  
      @Autowired
      private UserService userService;
  
      @RequestMapping(value = "/order/add", method = RequestMethod.GET)
      public String addOrder(Model model) {
          Order order = new Order();
          order.setOrderProducts(new AutoPopulatingList&lt;&gt;(OrderProduct.class));
          model.addAttribute("orderForm", order);
          model.addAttribute("products", productService.findAll());
          return "order/add";
      }
  
      @RequestMapping(value = "/order/add", method = RequestMethod.POST)
      public String addOrder(@ModelAttribute("orderForm") Order orderForm, BindingResult bindingResult, Model model) {
          orderForm.setUser(userService.findByUsername(securityService.findLoggedInUsername()));
          for (OrderProduct orderProduct : orderForm.getOrderProducts()) {
              orderProduct.setOrder(orderForm);
          }
          orderService.save(orderForm);
          return "redirect:/order/view";
      }
  }
  </code></pre>
  
  <p>And I want to create a form where a user can choose few products, give a quantity of them and submit his order. I was trying to write JSP code like that:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form:form method="POST" modelAttribute="orderForm"&gt;
      &lt;spring:bind path="orderProducts"&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;c:forEach items="${products}" var="product"&gt;
                      &lt;form:checkbox path="orderProducts[${product.id}].name"
                          value="${product.name}"
                          label="${product.name}"/&gt;
                      &lt;form:input type="text" path="orderProducts[${product.id}].quantity" placeholder="Quantity"/&gt;
                  &lt;/c:forEach&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/spring:bind&gt;
      &lt;button class="btn btn-lg btn-primary btn-block" type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>...but unfortunately it's probably trying to create as many orderProducts as I have in products list and as a result the orderProducts, which a service try to save, doesn't have properly setted values and at the end there is created an order without the orderProducts. So my question is how can I properly send the orderProducts via JSP code to the controller which finally will create the right order with its items?</p>