Until now, we have put the Hibernate related code inside the servlets. In other words, we are mixing the presentation logic and data access logic. | Hibernate Tutorial 14 Hibernate in Web Application 2 By Gary Mak hibernatetutorials@ September 2006 1. Organizing data access in Data Access Objects Until now we have put the Hibernate related code inside the servlets. In other words we are mixing the presentation logic and data access logic. This is absolutely not a good practice. In a multi-tier application the presentation logic and data access logic should be separated for better reusability and maintainability. There is a design pattern called Data Access Object DAO for encapsulating the data access logic. A good practice when using this pattern is that we should create one DAO for each persistent class and put all the data operations related to this class inside this DAO. public class HibernateBookDao public Book findById Long id SessionFactory factory Session session try Book book Book id return book finally public void saveOrUpdate Book book SessionFactory factory Session session Transaction tx null try tx book catch HibernateException e if tx null throw e finally Page 1 of 10 public void delete Book book SessionFactory factory Session session Transaction tx null try tx book catch HibernateException e if tx null throw e finally public List findAll SessionFactory factory Session session try Query query from Book List books return books finally public Book findByIsbn String isbn . public List findByPriceRange int fromPrice int toPrice . According to the object-oriented principles we should program to interface rather than to implementation. So we extract .