title: Optional int parameter '' is present but cannot be translated into a null value due to being declared as a primitive type
body: <p>BrandDao.java</p>
  
  <pre><code>package dao;
  
  import java.util.List;
  import model.pojo.Brands;
  import model.util.HibernateUtil;
  import org.hibernate.HibernateException;
  import org.hibernate.Query;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  
  
  public class BrandDao {
  
      public static List&lt;Brands&gt; list() {
          List&lt;Brands&gt; brands = null;
          try {
              Session session = HibernateUtil.getSessionFactory().openSession();
              Query query = session.createQuery("from Brands");
              brands = query.list();
  
              session.close();
          }
          catch (HibernateException ex) {
              ex.printStackTrace();
          }
          return brands;
      }
  
      public Brands getBrandById(int brandId) {
          SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
          Session session = sessionFactory.openSession();
          Transaction tx = session.beginTransaction();
          Brands brand = (Brands) session.get(Brands.class, brandId);
          tx.commit();
          session.close();
          return brand;
      }    
  
      public Brands addBrand(Brands brand) {
          try {
              SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
              Session session = sessionFactory.openSession();
              Transaction tx = session.beginTransaction();
              session.save(brand);
              tx.commit();
              session.close();
          } catch (HibernateException ex) {
              ex.printStackTrace();
          }
  
          return brand;
      }
  }
  </code></pre>
  
  <p>BrandsController.java</p>
  
  <pre><code>package controller;
  
  import dao.BrandDao;
  import java.io.IOException;
  import java.util.List;
  import model.pojo.Brands;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.multipart.MultipartFile;
  import org.springframework.web.servlet.ModelAndView;
  
  @Controller
  public class BrandsController {
  
      ModelAndView mav = new ModelAndView();
  
      @RequestMapping(value="/admin/brands")
      public ModelAndView index() {
          List&lt;Brands&gt; brands = BrandDa.list();
          mav.addObject("brands", brands); 
          mav.setViewName("brands-admin");
          return mav;
      } 
  
      @RequestMapping(value="/admin/brands/add", method = RequestMethod.POST)
      public String addBrand(@RequestParam("photo") MultipartFile photo, @RequestParam("brandName") String name) throws IOException {
  
          Brands brand = new Brands();
          BrandDao brandDao = new BrandDa();
          byte[] photoBytes = photo.getBytes();
          brand.setBrandLogo(photoBytes);
          brand.setBrandName(name);
          brandDao.addBrand(brand);
          return "redirect:/admin/brands";
      }     
  
      @RequestMapping(value="/admin/brands/getBrand", method = RequestMethod.GET)
      @ResponseBody
      public Brands getBrand(int brandId) {
          BrandDao brandDao = new BrandDa();
          return brandDao.getBrandById(brandId);
      }
  }
  </code></pre>
  
  <p>brands-admin.jsp</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
  &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt; 
          &lt;meta charset="UTF-8"&gt; 
          &lt;title&gt;House of Beauty&lt;/title&gt;
          &lt;link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/styles.css" /&gt;
          &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"&gt;
          &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"&gt;
          &lt;script src="https://code.jquery.com/jquery-3.4.0.min.js"&gt;&lt;/script&gt; 
          &lt;script&gt;
              $(document).ready(function() {
                  $('#getBrand').on('click', function(event) {
                     event.preventDefault();
                     var href = $(this).attr('href');
  
                     $.get(href, function(brand, status) {
                        $('#BrandForm #name').val(brand.getBrandName());
                        $('#BrandForm #photo').val(brand.getBrandLogo());
                     });
                     $('#BrandForm').modal('show');
                  });
              });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="modal fade" id="BrandForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
              &lt;div class="modal-dialog" role="document"&gt;
                  &lt;div class="modal-content"&gt;
                      &lt;div class="modal-header"&gt;
                          &lt;h5 class="modal-title w-100" id="myModalLabel"&gt;Edit brand&lt;/h5&gt;
                          &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                              &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                          &lt;/button&gt;
                      &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
                      &lt;form method="post" enctype="multipart/form-data" action="${pageContext.request.contextPath}/admin/brands/update"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input type="text" name="brandName" id="name" placeholder="Name" cssClass="form-control"/&gt;
                          &lt;/div&gt;    
                          &lt;div class="form-group"&gt;
                              &lt;input type="file" name="photo" id="photo"/&gt;
                          &lt;/div&gt;
                          &lt;div class="row form-bottom"&gt;
                              &lt;div class="col"&gt;
                                  &lt;input type="submit" value="Save" class="btn" id="btnAdd"&gt;
                                  &lt;input type="submit" value="Delete" class="btn" id="btnAdd"&gt;
                              &lt;/div&gt;  
                          &lt;/div&gt;
                      &lt;form&gt; 
                  &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;        
          &lt;div class="modal fade" id="AddBrandForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
              &lt;div class="modal-dialog" role="document"&gt;
                  &lt;div class="modal-content"&gt;
                      &lt;div class="modal-header"&gt;
                          &lt;h5 class="modal-title w-100" id="myModalLabel"&gt;Add brand&lt;/h5&gt;
                          &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                              &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                          &lt;/button&gt;
                      &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
                      &lt;form method="post" enctype="multipart/form-data" action="${pageContext.request.contextPath}/admin/brands/add"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input type="text" name="brandName" placeholder="Name" cssClass="form-control"/&gt;
                          &lt;/div&gt;    
                          &lt;div class="form-group"&gt;
                              &lt;input type="file" name="photo"/&gt;
                          &lt;/div&gt;
                          &lt;div class="row form-bottom"&gt;
                              &lt;div class="col"&gt;
                                  &lt;input type="submit" value="Add" class="btn" id="btnAdd"&gt;
                              &lt;/div&gt;  
                          &lt;/div&gt;
                      &lt;form&gt; 
                  &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;header&gt;
          ...
          &lt;div id="main_content"&gt;
              &lt;div class="container"&gt;
                  &lt;div class="row header-content"&gt;
                      &lt;div class="col title-page"&gt;
                          &lt;h3&gt;Brands&lt;/h3&gt; 
                      &lt;/div&gt; 
                      &lt;div class="col"&gt;
                          &lt;a href="#AddBrandForm" data-dismiss="modal" data-toggle="modal"&gt;Add brand&lt;/a&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;hr&gt;
                  &lt;div class="row"&gt;
                          &lt;c:forEach items="${brands}" var="brand"&gt; 
                              &lt;div class="col"&gt;
                                  &lt;div class="brand-item"&gt;
                                      &lt;a href="${pageContext.request.contextPath}/admin/brands/getBrand?id=&lt;c:out value="${brand.getBrandId()}"/&gt;" id="getBrand"&gt;
                                          &lt;div class="image"&gt;
                                              &lt;img src="${pageContext.request.contextPath}/images?id=&lt;c:out value="${brand.getBrandId()}"/&gt;" /&gt;
                                          &lt;/div&gt;
                                          &lt;p&gt;&lt;c:out value="${brand.getBrandName()}"/&gt;&lt;/p&gt;
                                      &lt;/a&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/c:forEach&gt;      
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;         
          &lt;script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"&gt;&lt;/script&gt; 
          &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"&gt;&lt;/script&gt;
          &lt;script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"&gt;&lt;/script&gt;        
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm trying to edit a brand from a modal just like I did to add it. I'm totally new with spring and hibernate and I don't know if I'm doing it the right way or not. By clicking on the link of the brand, which should open the modal, I get this error:</p>
  
  <pre><code>HTTP Status 500 - Internal Server Error
  type Exception report
  
  messageInternal Server Error
  
  descriptionThe server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Optional int parameter 'brandId' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
  root cause
  
  java.lang.IllegalStateException: Optional int parameter 'brandId' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
  note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.
  
  GlassFish Server Open Source Edition 4.1.1
  </code></pre>
  
  <p>Please, if someone can help me how to obtain the values of the brand and be able to edit it through the modal, I would greatly appreciate your help. Thanks in advance.</p>