// public User getUserById(String userId) // { // User user=null; // session = HibernateUtil.getSessionFactory().getCurrentSession(); // String hql = "FROM USER WHERE USER_ID= :userId"; // try // { // Query query = session.createQuery(hql); // query.setParameter("userId", userId); // user = (query.list() != null)? (User)query.list().get(0):null; // } // catch(Exception e) // { // e.printStackTrace(); // } // return user; // } public void initializeTransaction() { try { session = HibernateUtil.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction(); } catch (Exception e) { if (transaction != null) { transaction.rollback(); } e.printStackTrace(); } }
public void addDoctor(Doctor doctor) { try { session = HibernateUtil.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction(); session.save(doctor); System.out.println("Doctor with User is saved.."); } catch (Exception e) { if (transaction != null) { transaction.rollback(); } e.printStackTrace(); } transaction.commit(); }
@SuppressWarnings({"rawtypes", "unchecked"}) public List<Appointment> getAppointments(User user) { // List obj // Get all active appointments List<Appointment> appointmentList = new ArrayList(); session = HibernateUtil.getSessionFactory().getCurrentSession(); String hql; hql = "FROM APPOINTMENT WHERE ACTIVE = :active and user_id = :userId"; try { Query query = session.createQuery(hql); query.setParameter(":active", true); query.setParameter(":userId", user.getUserId()); appointmentList = (query.list() != null) ? (List<Appointment>) query.list() : null; } catch (Exception e) { e.printStackTrace(); } return appointmentList; }