hibernate - Insert not working in Spring MVC -


my question:

i have created spring mvc application, using hibernate.
table person getting created, data supply view not getting inserted. browsed through many sites, not being able point out mistake.

here files:

this homecontroller, have specified 2 request mappings, 1 root , fort save method**

    package com.controller;         @controller                   public class maincontroller {                    @autowired                     private personservice ps;                    @requestmapping("/")             public string home() {             return "index";         }          @requestmapping(value="/save",method=requestmethod.post)         public string save(@modelattribute person p) {             ps.save(p);             return "index";                 }             } 

this persondaoclass, contains save method

    package com.dao;             import com.model.person;             public interface persondao {         public void save(person p);     } 

here implementation of dao:

    @transactional     @repository     public class persondaoimpl implements persondao{         @autowired         private sessionfactory sessionfactory;                   public void save(person p) {             // todo auto-generated method stub             session s = sessionfactory.opensession();                sessionfactory.getcurrentsession();         //  transactional tx = (transactional) s.begintransaction();             s.persist(p);             s.flush();             s.close();         }            } 

this service class

    package com.service;              import com.model.person;             public interface personservice {         public void save(person p);     } 

this serviceimpl of service

package com.service;    @service public class personserviceimpl implements personservice{     @autowired     private persondao pdao;          public void setpersondao(persondao persondao) {         this.pdao = persondao;      }      @transactional     public void save(person p) {         // todo auto-generated method stub         this.pdao.save(p);     }        } 

finally, index.jsp

    <html>         <head>             <meta charset="utf-8">             <title>welcome</title>         </head>          <body>         <h2>hello world!</h2>             <form action="save" >             <!-- id : <input type="text" name="id"> -->             name : <input type="text" name="name"> <input type="submit"                 value="submit">         </form>          </body>     </html> 


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -