title: Java EE + Spring + Hibernate can't save UTF-8 characters into MySQL Database
body: <p>This question might be marked as duplicate, however, NONE of the StackOverflow answers didn't help me.
  I'm making a website using Java EE, Spring and Hibernate, with some other technologies, however, these are the only relevant ones.
  The website is a web store, and the admin should be able to add a product, it's name, price, manufacturer, etc...
  This is all working, everything on the website is working except saving the UTF-8 characters in the Database.
  The problem is not in the Database, it's all set to utf-8, and if I go to phpmyadmin, I can also change the characters in the desired format, and it will display properly.</p>
  
  <p>Here's the relevant product adding code...</p>
  
  <p><strong>Admin Product</strong></p>
  
  <pre><code>@Controller
  @RequestMapping("/admin")
  public class AdminProduct {
  
      private Path path;
  
      @Autowired
      ProductService productService;
  
  
  
      @RequestMapping("/product/addProduct")
      public String addProduct(Model model) {
  
          Product product = new Product();
          product.setProductCategory("toys");
          product.setProductStatus("available");
  
          model.addAttribute("product", product);
  
          return "addProduct";
  
  
      }
  
  
  
      @RequestMapping(value = "/product/addProduct", method = RequestMethod.POST)
      public String addProductPost(@Valid @ModelAttribute("product") Product product, BindingResult result, HttpServletRequest request) throws UnsupportedEncodingException {
          request.setCharacterEncoding("UTF-8");
          if(result.hasErrors()) {
              return "addProduct";
          }
  
          productService.addProduct(product);
  
          MultipartFile productImage = product.getProductImage();
          String rootDirectory = request.getSession().getServletContext().getRealPath("/");
  
          path = Paths.get(rootDirectory + "\\WEB-INF\\resources\\images\\" + product.getProductId() + ".png");
  
          if(productImage != null &amp;&amp; !productImage.isEmpty()) {
              try {
                  productImage.transferTo(new File(path.toString()));
              } catch(Exception e) {
                  throw new RuntimeException("Product image saving failed!");
              }
          }
  
          return "redirect:/admin/productInventory";
      }
  </code></pre>
  
  <p><strong>ProductDao Implementation</strong></p>
  
  <pre><code> @Repository
      @Transactional
      public class ProductDaoImpl implements ProductDao {
  
          @Autowired
          private SessionFactory sessionFactory;
  
      public Product getProductById(int id) {
          Session session = sessionFactory.getCurrentSession();
          Product product = (Product) session.get(Product.class, id);
          session.flush();
  
          return product;
      }
  
      public List&lt;Product&gt; getProductList() {
          Session session = sessionFactory.getCurrentSession();
          Query query = session.createQuery("from Product");
          List&lt;Product&gt; productList = query.list();
          session.flush();
          return productList;
      }
  
          public void  addProduct(Product product) {
              Session session = sessionFactory.getCurrentSession();
             session.saveOrUpdate(product);
              session.flush();
  
          }
  
          public void  editProduct(Product product) {
              Session session = sessionFactory.getCurrentSession();
              session.saveOrUpdate(product);
              session.flush();
  
          }
  
          public void  deleteProduct(Product product) {
              Session session = sessionFactory.getCurrentSession();
              session.delete(product);
              session.flush();
  
      }
  </code></pre>
  
  <p><strong>Product Model</strong></p>
  
  <pre><code>@Entity
  public class Product implements Serializable {
  
  
      private static final long serialVersionUID = -509245862136222627L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int productId;
  
      @NotEmpty (message = "Ime proizvoda ne moze biti prazno!")
      private String productName;
  
      private String productCategory;
      private String productDescription;
  
      @Min(value=0, message = "Cena proizvoda ne moze biti manja od nule!")
      private double productPrice;
  
      private String productCondition;
      private String productStatus;
  
      @Min(value=0, message = "Broj na lageru ne moze biti manji od nule!")
      private int unitInStock;
  
      private String productManufacturer;
  
      @Transient
      private MultipartFile productImage;
  
      @OneToMany(mappedBy = "product", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      @JsonIgnore
      private List&lt;CartItem&gt; cartItemList;
  
      public int getProductId() {
          return productId;
      }
  
      public void setProductId(int productId) {
          this.productId = productId;
      }
  
      public String getProductName() {
          return productName;
      }
  
      public void setProductName(String productName) {
          this.productName = productName;
      }
  
      public String getProductCategory() {
          return productCategory;
      }
  
      public void setProductCategory(String productCategory) {
          this.productCategory = productCategory;
      }
  
      public String getProductDescription() {
          return productDescription;
      }
  
      public void setProductDescription(String productDescription) {
          this.productDescription = productDescription;
      }
  
      public double getProductPrice() {
          return productPrice;
      }
  
      public void setProductPrice(double productPrice) {
          this.productPrice = productPrice;
      }
  
      public String getProductCondition() {
          return productCondition;
      }
  
      public void setProductCondition(String productCondition) {
          this.productCondition = productCondition;
      }
  
      public String getProductStatus() {
          return productStatus;
      }
  
      public void setProductStatus(String productStatus) {
          this.productStatus = productStatus;
      }
  
      public int getUnitInStock() {
          return unitInStock;
      }
  
      public void setUnitInStock(int unitInStock) {
          this.unitInStock = unitInStock;
      }
  
      public String getProductManufacturer() {
          return productManufacturer;
      }
  
      public void setProductManufacturer(String productManufacturer) {
          this.productManufacturer = productManufacturer;
      }
  
      public MultipartFile getProductImage() {
          return productImage;
      }
  
      public void setProductImage(MultipartFile productImage) {
          this.productImage = productImage;
      }
  
      public List&lt;CartItem&gt; getCartItemList() {
          return cartItemList;
      }
  
      public void setCartItemList(List&lt;CartItem&gt; cartItemList) {
          this.cartItemList = cartItemList;
      }
  }
  </code></pre>
  
  <p><strong>And finally the addProduct jsp page</strong></p>
  
  <pre><code>&lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  
      &lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
      &lt;html&gt;
      &lt;%@page pageEncoding="UTF-8"%&gt;
      &lt;%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
      &lt;%@include file="/WEB-INF/views/template/header.jsp" %&gt;
  
      &lt;div class="container-wrapper"&gt;
          &lt;div class="container"&gt;
  
              &lt;div class="page-header"&gt;
                  &lt;h1&gt;Dodaj Proizvod&lt;/h1&gt;
          &lt;p class="lead"&gt;Popunite informacije dole kako biste dodali proizvod:&lt;/p&gt;
  
              &lt;/div&gt;
  
              &lt;form:form action="${pageContext.request.contextPath}/admin/product/addProduct" method="post" commandName="product" enctype="multipart/form-data" acceptCharset="UTF-8"&gt;
  
                  &lt;div class="form-group"&gt;
                      &lt;label for="name"&gt;Ime&lt;/label&gt; &lt;form:errors path="productName" cssStyle="color:red"/&gt;
                      &lt;form:input path="productName" id="name" class="form-Control" acceptCharset="UTF-8"/&gt;
                  &lt;/div&gt;
       &lt;%--Category --%&gt;
              &lt;div class="form-group"&gt;
              &lt;label for="category"&gt;Kategorija&lt;/label&gt;
              &lt;label class="checkbox-inline"&gt;&lt;form:radiobutton  acceptCharset="UTF-8" path="productCategory" id="category" value="Školski/Kancelarijski pribor"/&gt; Školski/Kancelarijski pribor&lt;/label&gt;
              &lt;label class="checkbox-inline"&gt;&lt;form:radiobutton  acceptCharset="UTF-8" path="productCategory" id="category" value="Pokloni"/&gt; Pokloni&lt;/label&gt;
              &lt;label class="checkbox-inline"&gt;&lt;form:radiobutton  acceptCharset="UTF-8" path="productCategory" id="category" value="Igračke"/&gt; Igračke&lt;/label&gt;
              &lt;/div&gt;
  
       &lt;%--Description --%&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="description"&gt;Opis&lt;/label&gt;
                  &lt;form:textarea path="productDescription" id="description" class="form-Control" acceptCharset="UTF-8"/&gt;
              &lt;/div&gt;
      &lt;%--Price --%&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="price"&gt;Cena&lt;/label&gt; &lt;form:errors path="productPrice" cssStyle="color:red"/&gt;
                  &lt;form:input path="productPrice" id="price" class="form-Control"/&gt;
              &lt;/div&gt;
  
      &lt;%--Status --%&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="status"&gt;Status&lt;/label&gt;
                  &lt;label class="checkbox-inline"&gt;&lt;form:radiobutton path="productStatus" id="status" value="Dostupno"/&gt; Dostupno&lt;/label&gt;
                  &lt;label class="checkbox-inline"&gt;&lt;form:radiobutton path="productStatus" id="status" value="Nedostupno"/&gt; Nedostupno&lt;/label&gt;
  
              &lt;/div&gt;
  
                  &lt;%--Manufacturer --%&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="productManufacturer"&gt;Proizvođač&lt;/label&gt;
                  &lt;form:input path="productManufacturer" id="manufacturer" class="form-Control" acceptCharset="UTF-8"/&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;label class="control-label" for="productImage"&gt;Odaberi sliku&lt;/label&gt;
                  &lt;form:input id="productImage" path="productImage" type="file" class="form:input-large"/&gt;
              &lt;/div&gt;
  
              &lt;br&gt;&lt;br&gt;
  
              &lt;input type="submit" value="Dodaj" class="btn btn-default"&gt;
              &lt;a href="&lt;c:url value="/admin/productInventory"/&gt;" class="btn btn-default"&gt;Odustani&lt;/a&gt;
          &lt;/form:form&gt;
  
      &lt;%@include file="/WEB-INF/views/template/footer.jsp" %&gt;
  </code></pre>