package com.abc.dao; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Query; import com.abc.entities.Employee; import com.abc.exceptions.AppException; public class AdminDAOHibernateImpl extends DAO implements AdminDAO { public Employee create(Employee emp) throws AppException { try { begin(); getSession().save(emp); commit(); return emp; } catch (HibernateException e) { rollback(); throw new AppException(e.getCause().getMessage()); } } public void delete(Employee emp) throws AppException { try { begin(); getSession().delete(emp); commit(); } catch (HibernateException e) { rollback(); throw new AppException(e.getCause().getMessage()); } } public Employee get(Integer psno) throws AppException { try { Query q = getSession().createQuery( "from Employee e inner join fetch e.dept where e.psno = :psno"); q.setString("psno", psno.toString()); Employee emp = (Employee) q.uniqueResult(); return emp; } catch (HibernateException e) { throw new AppException(e.getCause().getMessage()); } } public void save(Employee emp) throws AppException { try { begin(); getSession().update(emp); commit(); } catch (HibernateException e) { rollback(); throw new AppException(e.getCause().getMessage()); } } @SuppressWarnings("unchecked") public List list() throws AppException { try{ Query q = getSession().createQuery("from Employee"); List list = q.list(); return list; }catch(HibernateException e){ throw new AppException(e.getCause().getMessage()); } } public List list(int firstResult, int maxResults) throws AppException { try{ Query q = getSession().createQuery("from Employee"); q.setFirstResult(firstResult); q.setMaxResults(maxResults); List list = q.list(); System.out.println(list.size()); return list; }catch(HibernateException e){ throw new AppException(e.getCause().getMessage()); } } }