Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. public class UserDAO {
  2. private SessionFactory sessionFactory;
  3.  
  4. public UserDAO() {
  5. sessionFactory = HibernateUtil.getSessionFactory();
  6. }
  7.  
  8. /* public void dodajGatunek(Gatunek a) {
  9. try {
  10. if (!sessionFactory.getCurrentSession().getTransaction().isActive()) {
  11. sessionFactory.getCurrentSession().getTransaction().begin();
  12. }
  13. sessionFactory.getCurrentSession().save(a);
  14. sessionFactory.getCurrentSession().getTransaction().commit();
  15. } catch (Exception e) {
  16. sessionFactory.getCurrentSession().getTransaction().rollback();
  17. throw e;
  18. }
  19. }*/
  20.  
  21. @SuppressWarnings("unchecked")
  22. public List<User> getUsers(){
  23. try {
  24. if(!sessionFactory.getCurrentSession().getTransaction().isActive()) {
  25. sessionFactory.getCurrentSession().getTransaction().begin();
  26. }
  27. return sessionFactory.getCurrentSession().createCriteria(User.class).list();
  28. }catch(Exception e) {
  29. return null;
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement