List of usage examples for org.hibernate Session setCacheMode
void setCacheMode(CacheMode cacheMode);
From source file:com.model.dao.DepartmentDao.java
public static List<Department> list() { List<Department> result = null; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;// w w w. j a va2 s . com try { tx = session.beginTransaction(); result = session.createQuery("from com.model.entity.Department").list(); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); } ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.EmployeeDao.java
public static boolean addEmploye(Employee e) { boolean result = false; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;/*from ww w . j av a2s. c o m*/ try { tx = session.beginTransaction(); session.merge(e); tx.commit(); result = true; } catch (HibernateException ex) { if (tx != null) { tx.rollback(); result = false; } ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.EmployeeDao.java
public static boolean deleteEmploye(Employee e) { boolean result = false; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;//w w w .ja v a 2 s .c om try { tx = session.beginTransaction(); session.delete(e); tx.commit(); result = true; } catch (HibernateException ex) { if (tx != null) { tx.rollback(); result = false; } ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.EmployeeDao.java
public static boolean updateEmploye(Employee e) { boolean result = false; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;//from ww w . j av a2s . com try { tx = session.beginTransaction(); session.update(e); tx.commit(); result = true; } catch (HibernateException ex) { if (tx != null) { tx.rollback(); result = false; } ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.EmployeeDao.java
public static List<Employee> list() { Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;/*from w w w . j a va 2 s .c om*/ List<Employee> result = null; try { tx = session.beginTransaction(); result = session.createQuery("FROM Employee").list(); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); } ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.EmployeeDao.java
public static Employee login(String email, String password) { Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;//w ww. j a va2 s . c o m Employee result = null; try { tx = session.beginTransaction(); Query q = session.createQuery("FROM Employee where email = :email and password = :password"); q.setParameter("email", email); q.setParameter("password", password); result = (Employee) q.list().get(0); tx.commit(); } catch (Exception ex) { if (tx != null) { tx.rollback(); } ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.VacationDao.java
public static boolean addVacation(Vacation v) { boolean result = false; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;//from ww w .j a v a 2 s.co m try { tx = session.beginTransaction(); session.save(v); tx.commit(); result = true; } catch (HibernateException ex) { if (tx != null) { tx.rollback(); result = false; } ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.VacationDao.java
public static List<Vacation> listMyVacations(long emp_id) { List<Vacation> result = null; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;//from w ww .java 2 s .c o m try { tx = session.beginTransaction(); Query q = session.createQuery("FROM Vacation Where employee.id = :emp_id order by requestedAt DESC"); q.setParameter("emp_id", emp_id); result = q.list(); tx.commit(); } catch (HibernateException ex) { if (tx != null) tx.rollback(); ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.VacationDao.java
public static List<Vacation> listDepartmentVacations(long department_id) { List<Vacation> result = null; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;//from w ww. j a v a 2 s. co m try { tx = session.beginTransaction(); Query q = session .createQuery("FROM Vacation Where employee.department.id = :dep_id AND status = 'Pending'"); q.setParameter("dep_id", department_id); result = q.list(); tx.commit(); } catch (HibernateException ex) { if (tx != null) tx.rollback(); ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.model.dao.VacationDao.java
public static boolean dmReject(Vacation v) { boolean result = false; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;//from w ww. j a va 2s .co m try { tx = session.beginTransaction(); v.setStatus(Vacation.VacationStatus.RejectedByDepartmentManager); session.update(v); tx.commit(); result = true; } catch (HibernateException ex) { if (tx != null) { tx.rollback(); result = false; } ex.printStackTrace(); } finally { session.close(); } return result; }