title: want to delete a record from the database in spring mvc
body: <p>I am trying CRUD example in spring mvc.I am able to save the user to the database but i am not able to delete an entry from the database table.My spring controller class is as follows</p>
  
  <p>CController.java</p>
  
  <pre><code>    package project4;
      import project4.UserDAO1;
      import project4.User1;
      import java.util.Map;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import org.springframework.stereotype.Controller;
      import org.springframework.transaction.annotation.Transactional;
      import org.springframework.ui.ModelMap;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
      import org.springframework.web.servlet.ModelAndView;
      import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
      import org.springframework.web.bind.annotation.ModelAttribute;
      import org.springframework.validation.BindingResult;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.beans.factory.annotation.Qualifier;
  
  
      @Controller
  
  
  
  
  public class CController{
  
  private UserDAO1 userDAO;
  @Autowired
  @Qualifier("myUserDAO")
  private UserDAOImpl1 myUserDAO;
  
  public void setUserDAO(UserDAO1 userDAO) {
      this.userDAO = userDAO;
  }
  
      @RequestMapping(value = "/frm4/add", method = RequestMethod.POST)
  public ModelAndView add( @ModelAttribute("add") User1 user,HttpServletRequest request,
          HttpServletResponse response) throws Exception {
           System.out.println("hai");
  
      userDAO.saveUser(user);
      System.out.println("hai");
      return new ModelAndView("redirect:/list.htm");
  }
  
      @RequestMapping(params = "/deletedpage/delete", method = RequestMethod.POST)
      @Transactional
      public ModelAndView delete(@ModelAttribute("delete") User1 user,HttpServletRequest request,
          HttpServletResponse response) throws Exception {
          System.out.println("hai");
      userDAO.deleteUser(user);
      return new ModelAndView("redirect:/list.htm");
  }
  
  
      @RequestMapping(params = "find", method = RequestMethod.POST)
      @Transactional
      public ModelAndView find(@ModelAttribute("find") User1 user,HttpServletRequest request,
              HttpServletResponse response) throws Exception {  
                       userDAO.findUser(user);
                        return new ModelAndView("redirect:list.htm");
      }
  
  
      @RequestMapping(params = "update", method = RequestMethod.POST)
      @Transactional
      public ModelAndView update(@ModelAttribute("update") User1 user,HttpServletRequest request,
              HttpServletResponse response) throws Exception {  
                       userDAO.updateUser(user);
                        return new ModelAndView("redirect:list.htm");
      }
  
  
      @RequestMapping(value = "list", method = RequestMethod.GET)
  public ModelAndView list(HttpServletRequest request,
          HttpServletResponse response) throws Exception {
  
  
      ModelMap modelMap = new ModelMap();
      modelMap.addAttribute("userList", userDAO.listUser());
      modelMap.addAttribute("user", new User1());
      return new ModelAndView("list", modelMap);
  }
  }
  </code></pre>
  
  <p>and my hibernate template class is as follows</p>
  
  <p>UserDAOImpl1.java</p>
  
  <pre><code>    package project4;
      import project4.User1;
      import java.util.List;
      import org.hibernate.Query;
      import org.hibernate.Session;
      import org.hibernate.SessionFactory;
      import org.hibernate.cfg.Configuration;
      import org.springframework.orm.hibernate3.HibernateTemplate;
      import org.springframework.transaction.annotation.Propagation;
      import org.springframework.transaction.annotation.Transactional;
  
  public class UserDAOImpl1 implements UserDAO1 {
  
  private HibernateTemplate hibernateTemplate;
  
  public void setSessionFactory(SessionFactory sessionFactory) {
      this.hibernateTemplate = new HibernateTemplate(sessionFactory);
  }
  
  @Override
  @Transactional(propagation=Propagation.REQUIRED, readOnly=false)
  public void saveUser(User1 user) {
      try {
       System.out.println (user.getId ());
      hibernateTemplate.save(user);
      }catch (RuntimeException re){
          throw re;
      }
  }
  
  @Override
  @SuppressWarnings("unchecked")
  public List&lt;User1&gt; listUser() {
      List&lt;User1&gt; result = hibernateTemplate.find("from User1");
      System.out.println("hai");      
      return result;
  }
  
      @Override
  public void deleteUser(Long id1) {
      System.out.println(id1);
      hibernateTemplate.delete("from User1 where USER_ID=:" +id1);
      System.out.println("hello");
  }
  
      @Override
      public List&lt;User1&gt; findUser(User1 user) {
          List&lt;User1&gt; result =hibernateTemplate.find("from User1 where USER_ID=:" +user.getId());
          return result;
  
      }
  
      @Override
      public void updateUser(User1 user) {
          hibernateTemplate.update(user);
  
      }
  }
  </code></pre>
  
  <p>and my user dao class is as follows</p>
  
  <p>User1.java</p>
  
  <pre><code> package project4;
   import javax.persistence.Column;
   import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
    @Entity
    @Table(name="user")
    public class User1 {
  
          private long id;
          private String name;
          private String password;
          private String gender;
          private String country;
          private int oid;
  
          @Id
          @GeneratedValue
          @Column(name="USER_OID")
          public int getOid(){
                   return oid;
          }
  
          public void setOid(int id){
              this.oid=id;
          }
  
  
  
         @Column(name="USER_ID")
         public long getId() {
              return id;
          }
          public void setId(long id) {
               this.id = id;
          }
  
  
  
          @Column(name="USER_NAME")
          public String getName() {
               return name;
          }
          public void setName(String name) {
                 this.name = name;
          }
  
          @Column(name="USER_PASSWORD")
          public String getPassword() {
              return password;
           }
          public void setPassword(String password) {
             this.password = password;
          }
  
          @Column(name="USER_GENDER")
          public String getGender() {
                  return gender;
          }
          public void setGender(String gender) {
               this.gender = gender;
          }
  
          @Column(name="USER_COUNTRY")
          public String getCountry() {
                return country;
          }
         public void setCountry(String country) {
            this.country = country;
         }
   }
  </code></pre>
  
  <p>I have two id feild,oid is for storing the value which is generated by default and id stores the value got from the user</p>
  
  <p>now when i try to delete a user i get </p>
  
  <pre><code>SEVERE: Servlet.service() for servlet CController threw exception
  org.hibernate.MappingException: Unknown entity: java.lang.String
  at   
  org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:693)
  at  
    org.hibernate.impl.SessionImpl.getEntityPersister
  
   org.hibernate.event.def.DefaultDeleteEventListener.
      onDelete(DefaultDeleteEventListener.java:99)
  at org.hibernate.event.def.DefaultDeleteEventListener.
      onDelete(DefaultDeleteEventListener.java:73)
  at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:956)
  at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:934)
  at org.springframework.orm.hibernate3.HibernateTemplate$25.
          doInHibernate(HibernateTemplate.java:843)
  at org.springframework.orm.hibernate3.HibernateTemplate.
         doExecute(HibernateTemplate.java:406)
  at org.springframework.orm.hibernate3.HibernateTemplate.
        executeWithNativeSession(HibernateTemplate.java:374)
  at org.springframework.orm.hibernate3.HibernateTemplate.
           delete(HibernateTemplate.java:837)
  at org.springframework.orm.hibernate3.HibernateTemplate.
                   delete(HibernateTemplate.java:833)
  at project4.UserDAOImpl1.deleteUser(UserDAOImpl1.java:50)
  at project4.CController.delete(CController.java:52)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.
           invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.springframework.web.bind.annotation.support.
        HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
  at org.springframework.web.servlet.mvc.annotation. AnnotationMethodHandlerAdapter.
          invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
  at org.springframework.web.servlet.mvc.annotation.
           AnnotationMethodHandlerAdapter.
              handle(AnnotationMethodHandlerAdapter.java:424)
  at org.springframework.web.servlet.DispatcherServlet.
         doDispatch(DispatcherServlet.java:790)
  at org.springframework.web.servlet.DispatcherServlet.
                doService(DispatcherServlet.java:719)
  at org.springframework.web.servlet.FrameworkServlet.
              processRequest(FrameworkServlet.java:669)
  at org.springframework.web.servlet.FrameworkServlet.
           doPost(FrameworkServlet.java:585)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  at org.apache.catalina.core.ApplicationFilterChain.
             internalDoFilter(ApplicationFilterChain.java:290)
  at org.apache.catalina.core.ApplicationFilterChain.
           doFilter(ApplicationFilterChain.java:206)
  at org.apache.catalina.core.StandardWrapperValve.
             invoke(StandardWrapperValve.java:233)
  at org.apache.catalina.core.StandardContextValve.
           invoke(StandardContextValve.java:175)
  at org.apache.catalina.core.StandardHostValve.
            invoke(StandardHostValve.java:128)
  at org.apache.catalina.valves.ErrorReportValve.
             invoke(ErrorReportValve.java:102)
  at org.apache.catalina.core.StandardEngineValve.
              invoke(StandardEngineValve.java:109)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.
        process(Http11Protocol.java:583)
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  at java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>So when i try to delete a user with id 23 i am able to pass the value from the jsp to the controller and then to the delete function inside the hibernate template class where i print the id and the value 23 is successfully printed.But the delete query is not getting executed.Is there any  error in the query??</p>