How to insert data into the database using spring + hibernate?
05:15 25 Sep 2014

see i m havving user.java for the user info.

@Entity(name = "user")
@Table(name = "user")
public class User {

    @Id
    @Column(name = "id")
    private String id;  
    @Column(name = "password")
    private String password;
//getter and setter for this..
}

this is my userdao

public class UserDao {
    public interface UserDAO {
        public String insert(User user);

    }
}

and this is the impl class for inserting into database see this was my code.please check it and tell me what i m doing wrong

@Repository
@Transactional
public class UserImpl implements UserDAO {

    private DataSource dataSource;

    @Autowired
    SessionFactory sessionFactory;
    @Resource(name = "sessionFactory")
    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Override
    public String insert(User use) {

        Session session = this.sessionFactory.openSession();
        try{

            Session sess = this.sessionFactory.getCurrentSession();              
            session.save(reg);


                        return (String)user.getUserName(); 
                        }catch(Exception e){
                            System.out.println("in catch"+e.getMessage());
                            e.printStackTrace();

    }

    }
}




} 

and in my controller after successful registration i m inserting data to the database by this

 userDao.insert(user);

but i m not getting output means not any data is inserting into the database.why this..? this is my mvc configuration


    
    
    
        
        

    
java mysql spring hibernate