title: A null value cannot be assigned to a primitive type error (Spring/Hibernate)
body: <p>I have 3 tables in my database - Booking, Restaurant and RestaurantTable. Right now I am trying to create a new booking and one of the steps there is adding a table.  When I try to add this table the following error comes up:</p>
  
  <pre><code> org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.persistence.Column int for value 'null'; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type
  </code></pre>
  
  <p>I don't know why it gives that error, since the table I am trying to add is not null (I think at least). Hope you understand what I mean.</p>
  
  <p>My Booking table in the database:</p>
  
  <pre><code>CREATE TABLE `booking` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `R_id` int(11) NOT NULL,
    `date` date not null,
    `start` TEXT,
    `duration` float(3,1),
    `amount_of_people` int,
    `name` TEXT,
    `contact_preference` TEXT,
    `phone_number` TEXT,
    `comments` TEXT,
    `current_datetime` datetime default current_timestamp,
    `new_date` datetime default current_timestamp,
    `deleted` bool default false,
    `edited` bool default false,
    `table_number` int,
    PRIMARY KEY (`id`),
    FOREIGN KEY (`R_id`) references `restaurant`(`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
  /*!40101 SET character_set_client = @saved_cs_client */;
  </code></pre>
  
  <p>My RestaurantTable in the database:</p>
  
  <pre><code>CREATE TABLE `restaurant_table` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `table_size` int,
    `table_number` int,
    `restaurant_id` int(11),
    PRIMARY KEY (`id`),
    FOREIGN KEY (`restaurant_id`) references `restaurant`(`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
  /*!40101 SET character_set_client = @saved_cs_client */;
  </code></pre>
  
  <p>The .jsp file of the table I am trying to add to the booking:</p>
  
  <pre><code>&lt;body&gt;
  &lt;jsp:include page="../fragments/menu.jsp"/&gt;
  &lt;div id="body"&gt;
      &lt;h2&gt;Create new booking&lt;/h2&gt;
  
      &lt;form:form method="POST" modelAttribute="booking" &gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Choose a table*:&lt;/td&gt;
                  &lt;td&gt;&lt;form:select path="tableNumber"&gt;
                          &lt;form:option value="" label="--- Select ---" /&gt;
                          &lt;form:options items="${tables}" itemValue="tableNumber" itemLabel="tableNumber"/&gt;
                  &lt;/form:select&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="3"&gt;&lt;input type="submit" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form:form&gt;
      &lt;div&gt;
          &lt;a href="/bookings"&gt;Back to List&lt;/a&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;jsp:include page="../fragments/footer.jsp"/&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>Relevant methods in BookingController.java:</p>
  
  <pre><code>@RequestMapping(value = "booking/create/{id}", method = RequestMethod.GET)
  public String chooseTable(@PathVariable Long id, Model model) {
      Booking booking = bookingService.getBooking(id);
      Restaurant restaurant = booking.getRestaurant();
      Set&lt;RestaurantTable&gt; tableSet = restaurant.getTable();
      model.addAttribute("tables", tableSet);
      model.addAttribute("booking", booking);
      return "chooseTable";
  }
  
  @RequestMapping(value = "booking/create/{id}", method = RequestMethod.POST)
  public String chooseTableAction(@PathVariable Long id, Model model) {
      return "redirect:/bookings";
  }
  </code></pre>
  
  <p>Right now the POST method in the booking controller doesn't do anything since it's giving me an error even before that.</p>
  
  <p>Any help is appreciated!</p>