title: Spring mvc DELETE WITH classic POST (@PostMapping) not working
body: <p>hi i'm testing a fast crud with spring mvc using classic methods as forms types</p>
  
  <p>the error is this</p>
  
  <pre><code>org.springframework.dao.EmptyResultDataAccessException: No class 
  com.project.springinventory.entity.Customers entity with id 0 exists!
          at 
  org.springframework.data.jpa.repository.support.SimpleJpaRepository.delete(SimpleJpaRepository.java:154) ~[spring-data-jpa-1.11.10.RELEASE.jar:na]
  </code></pre>
  
  <p>looks like the object is not receiving anything</p>
  
  <p>checked anything and looks ok I don't know what to do</p>
  
  <p>as you can see I'm receiving id and obtaining all fields from DB
  is there a manner I can use this method without changing it? (using form)</p>
  
  <p><img src="https://i.stack.imgur.com/3ALWW.jpg" alt="Click here to view image"></p>
  
  <p>VIEW </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table class="table table-bordered"&gt;
   &lt;tr&gt;
    &lt;th&gt;&lt;span&gt;Id&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span&gt;Course&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span&gt;Name&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span&gt;Last Name&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span&gt;Address&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span&gt;Actions&lt;/span&gt;&lt;/th&gt;
   &lt;/tr&gt;
   &lt;tr th:each="customer:${customers}"&gt;
    &lt;th&gt;&lt;span th:text="${customer.id}"&gt;&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span th:text="${customer.firstname}"&gt;&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span th:text="${customer.lastname}"&gt;&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span th:text="${customer.course}"&gt;&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;&lt;span th:text="${customer.address}"&gt;&lt;/span&gt;&lt;/th&gt;
    &lt;th&gt;
     &lt;form th:action="@{/showCustomer}" th:object="${customers}" method="post"&gt;
      &lt;input type="submit" name="btnInsert" class="btn btn-primary" value="Add" /&gt;
     &lt;/form&gt;
     &lt;form th:action="@{/UpdateCustomer}" th:object="${customers}" method="post"&gt;
      &lt;button class="btn btn-warning"&gt;
       &lt;span class="glyphicon glyphicon-pencil" aria-hidden="true"&gt;Edit&lt;/span&gt;
      &lt;/button&gt;
     &lt;/form&gt;
     &lt;form th:action="@{/DeleteCustomer}" th:object="${customers}" method="post"&gt;
      &lt;input type="submit" name="btnInsert" class="btn btn-primary" value="Delete" /&gt;
     &lt;/form&gt;
       &lt;/th&gt;
   &lt;/tr&gt;
   &lt;form action="#" th:action="@{/customermanagement}" th:object="${CustomersAdd}" method="post"&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;input type="text" placeholder="Course"
      th:field="*{course}" /&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" placeholder="Name"
      th:field="*{firstname}" /&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" placeholder="Last Name"
      th:field="*{lastname}" /&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" placeholder="Address"
      th:field="*{address}" /&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input type="submit" name="btnInsert"
      class="btn btn-primary" value="Add" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;
      &lt;p th:if="${#fields.hasErrors('course')}" th:errors="*{course}"&gt;course
       has errors&lt;/p&gt;
     &lt;/td&gt;
     &lt;td&gt;
      &lt;p th:if="${#fields.hasErrors('firstname')}"
       th:errors="*{firstname}"&gt;firstname has errors&lt;/p&gt;
     &lt;/td&gt;
     &lt;td&gt;
      &lt;p th:if="${#fields.hasErrors('lastname')}"
       th:errors="*{lastname}"&gt;lastname has errors&lt;/p&gt;
     &lt;/td&gt;
     &lt;td&gt;
      &lt;p th:if="${#fields.hasErrors('address')}"
       th:errors="*{address}"&gt;address has errors&lt;/p&gt;
     &lt;/td&gt;
    &lt;/tr&gt;    
   &lt;/form&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>CONTROLLER      </p>
  
  <pre><code>@PostMapping("/DeleteCustomer")
          public ModelAndView DeleteUser(@ModelAttribute("customers") Customers 
          Customers) {
          ModelAndView mav = new ModelAndView();
  
          System.err.println("Deleting:");
          System.err.println("getId " + Customers.getId());
          System.err.println("getCourse " + Customers.getCourse().toString());
          System.err.println("getCourse " + Customers.getFirstname().toString());
          System.err.println("getLastname " + Customers.getLastname().toString());
          System.err.println("getAddress " + Customers.getAddress().toString());
          customersService.removeCustomer(Customers.getId());
          customersService.listAllCustomers();
          mav.setViewName("redirect:/" + MAIN_VIEW);
          return mav;
  
      }
  
  SERVICE
  
      public interface CustomersService {
  
      public abstract List&lt;Customers&gt; listAllCustomers();
      public abstract Customers addCustomer(Customers customers);
      public abstract int removeCustomer(int  id);
      public abstract Customers updateCustomer(Customers customers);
  
  }
  </code></pre>
  
  <p>SERVICE IMPLEMENTATION</p>
  
  <pre><code>    package com.project.springinventory.services;
  
      import java.util.List;
  
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.beans.factory.annotation.Qualifier;
      import org.springframework.stereotype.Service;
  
      import com.project.springinventory.entity.Customers;
      import com.project.springinventory.repository.CustomersJpaRepository;
  
      @Service("customersServiceImpl")
      public class CustomersServiceImpl implements CustomersService {
  
      @Autowired
      @Qualifier("customersJpaRepository")
      private CustomersJpaRepository customersJpaRepository;  
  
      @Override
      public List&lt;Customers&gt; listAllCustomers() {
          // TODO Auto-generated method stub
          return  customersJpaRepository.findAll();
      }
  
      @Override
      public Customers addCustomer(Customers customers) {
          // TODO Auto-generated method stub
          return customersJpaRepository.save(customers);
      }
  
      @Override
      public int removeCustomer(int id) {
          // TODO Auto-generated method stub
          customersJpaRepository.delete(id);
          return 0;
      }
  
      @Override
      public Customers updateCustomer(Customers customers) {
          // TODO Auto-generated method stub
          return customersJpaRepository.save(customers);
      }
  
  ''
  
  }
  </code></pre>
  
  <p>Literally everything is working exception the DELETE</p>