Create a interface in src/java/projectname/dao/EmployeeDAO
DAO aka Data Access Object, is the “model” of MVC.
1 2 3 4 5 6 7 8 9 10 11
publicinterfaceEmployeeDAO {
public List<Employee> findAll();
public Employee findById(int theId);
publicvoidsave(Employee theEmployee);
publicvoiddelete(Employee theEmployee);
}
Implementing the interface in src/java/projectname/dao/EmployeeDAOHibernateImpl
@Repository
contains the api to control the database; -. createQuery(…)
.get(…)
etc…
@Transactional
transaction is atom unit of the DBMS, Provides a way for database operation sequences to recover from failure to a normal state. DBMS needs to ensure that all operations in the transaction are completed successfully and the results are permanently stored in the database. IF some operations in the transaction are not completed successfully, all operations in the transaction need to be rolled back to the state before the transaction has no effect on the database or the execution of other transactions, and all transactions needs to be executed independently.