<repo_name>mohibkhan-nedian/Student-Management-System-RESTful-Webservice<file_sep>/src/main/java/com/springapp/mvc/dao/Studentdaoimpl.java
package com.springapp.mvc.dao;

import com.springapp.mvc.domain.Student;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * Created by mohib on 10/27/2015.
 */
@Repository
public class Studentdaoimpl implements Studentdao {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public void insert(Student student) {
        sessionFactory.getCurrentSession().saveOrUpdate(student);
    }

    @Override
    public void delete(int id) {
        Student student =(Student)sessionFactory.getCurrentSession().get(Student.class,id);
        sessionFactory.getCurrentSession().delete(student);
    }

    @Override
    public Student getStudentById(int id){
        Student student =(Student)sessionFactory.getCurrentSession().get(Student.class,id);
        return  student;
    }

    @Override
    public
    Student update(int id,String name){
        Student student =(Student)sessionFactory.getCurrentSession().get(Student.class,id);
        student.setName(name);
        sessionFactory.getCurrentSession().saveOrUpdate(student);
        return  student;
    }

    @Override
    public Student update(int id, int age, String name){
        Student student =(Student)sessionFactory.getCurrentSession().get(Student.class,id);
        student.setName(name);
        student.setAge(age);
        sessionFactory.getCurrentSession().saveOrUpdate(student);
        return  student;
    }

}
<file_sep>/README.md
# Student-Management-System-RESTful-Webservice
A RESTful web service for managing student records developed using Java, Spring Framework, JSP and Hibernate with MySQL.
<file_sep>/src/main/java/com/springapp/mvc/service/StudentServiceImpl.java
package com.springapp.mvc.service;

import com.springapp.mvc.dao.Studentdao;
import com.springapp.mvc.dao.Studentdaoimpl;
import com.springapp.mvc.domain.Student;
import com.springapp.mvc.dto.StudentDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by mohib on 10/27/2015.
 */

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private Studentdao studentdao; // actually object of studentdaoimpl is created, see mvc-dispatcher-servlet.xml

    @Override
    @Transactional
    public void insert(Student student) {
        studentdao.insert(student);
    }

    @Override
    @Transactional
    public void delete(int id ){

        studentdao.delete(id);
    }

    @Override
    @Transactional
    public Student update( int id, String name ){
        Student student = studentdao.update( id, name);
        return student;
    }
    @Override
    @Transactional
    public Student update(int id, int age, String name ){

        Student student = studentdao.update( id, age, name);
        return student;
    }
    @Override
    @Transactional
    public Student getStudentById(int id) {

        Student student = (Student)studentdao.getStudentById(id);
        return student;

    }


}
<file_sep>/src/main/java/com/springapp/mvc/service/StudentService.java
package com.springapp.mvc.service;

import com.springapp.mvc.dao.Studentdao;
import com.springapp.mvc.domain.Student;

/**
 * Created by mohib on 10/27/2015.
 */
// although dao and service interfaces are usually same...following is wrong, studentservice shouldnt extend dao
public interface StudentService extends Studentdao{
 // made another interface for studentservice to add some special behavior if required other than defined in dao

}
