i am new to spring and also hibernate . That is a simple crud app. Include and delete functions . when i edit and hit submit i obtain this exception. HTTP condition 500 - Request processing failed; nested exception is java.lang.NullPointerException -------------------------------------------------------------------------------- kind Exception report post Request handling failed; nested exception is java.lang.NullPointerException description The server encountered an inner error the prevented it from fulfilling this request. exemption org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563) javax.servlet.http.HttpServlet.service(HttpServlet.java:646) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause java.lang.NullPointerException com.mayur.dao.ProductDAOImpl.updateProduct(ProductDAOImpl.java:36) com.mayur.service.ProductServiceImpl.updateProduct(ProductServiceImpl.java:34) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307) org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) com.sun.proxy.$Proxy19.updateProduct(Unknown Source) com.mayur.Controller.ProductController.editProduct(ProductController.java:75) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563) javax.servlet.http.HttpServlet.service(HttpServlet.java:646) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ----------------------------------------------------------------------------------------------------------------------------- complying with are other files Product.java


You are watching: Http status 500 - request processing failed; nested exception is java.lang.nullpointerexception

Column(name="QUANTITY")private int quantity;public essence getId() return id;public void setId(Integer id) this.id = id;public string getProductName() return productName;public void setProductName(String productName) this.productName = productName;public int getPrice() return price;public void setPrice(int price) this.price = price;public int getQuantity() return quantity;public void setQuantity(int quantity) this.quantity = quantity;} ProductDAOImpl.java
Autowiredprivate SessionFactory sessionFactory;public void addProduct(Product product) sessionFactory.getCurrentSession().save(product);public void removeProduct(int id) Product product = getProductById(id); if(null != product) sessionFactory.getCurrentSession().delete(product);
SuppressWarnings("unchecked") public list listProducts() return sessionFactory.getCurrentSession().createQuery("from Product").list(); publicly void updateProduct(Product product) Product productToUpdate = getProductById(product.getId()); productToUpdate.setProductName(product.getProductName()); productToUpdate.setPrice(product.getPrice()); productToUpdate.setQuantity(product.getQuantity()); sessionFactory.getCurrentSession().update(productToUpdate); windy Product getProductById(int id) Product product =(Product)sessionFactory.getCurrentSession().get(Product.class,id); return product; } ProductServiceImpl.java
Transactionalpublic Product getProductById(int id) return productDAO.getProductById(id); ProductController.java
Controller
SessionAttributes public class ProductController
Autowired private ProductService productService;
RequestMapping("addproduct.html") windy String viewaddProduct(Map model) Product product = brand-new Product(); model.put("product", product); return "addproduct";
ModelAttribute("product") Product product, BindingResult bindingresult, Map model) if (bindingresult.hasErrors()) return "addproduct"; productService.addProduct(product); model.put("productList", productService.listProducts()); return "listproduct";
ModelAttribute("product") Product product, Map model) productService.removeProduct(id); model.put("productList", productService.listProducts()); return "redirect:/listproduct.html";
RequestMapping("listproduct.html") windy String listProducts(Map model) model.put("productList", productService.listProducts()); return "listproduct";
PathVariable("id")Integer id, Map model) model.put("product", productService.getProductById(id)); return "editproduct";


See more: How Do People Level So Fast?: 7 Days To Die How To Level Up Fast

ModelAttribute("product") Product product, Map model) productService.updateProduct(product); model.put("productList", productService.listProducts()); return "redirect:/listproduct.html"; please help me.