Guest User

Untitled

a guest
May 7th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public AbstractUser login(String username, String password){
  2. //Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
  3. //SessionFactory sessionFactory= cfg.buildSessionFactory();
  4. SessionFactory sessionFactory;
  5. sessionFactory = new AnnotationConfiguration()
  6. .addAnnotatedClass(AbstractUser.class)
  7. .addAnnotatedClass(CourseSession.class)
  8. .addAnnotatedClass(Course.class)
  9. .addAnnotatedClass(Message.class)
  10. .addAnnotatedClass(Material.class)
  11. .addAnnotatedClass(TopicSession.class)
  12. .addAnnotatedClass(Step.class)
  13. .addAnnotatedClass(Section.class)
  14. .addAnnotatedClass(Topic.class)
  15. .addAnnotatedClass(Subtopic.class)
  16. .configure("hibernate.cfg.xml")
  17. .buildSessionFactory();
  18. sessionFactory.openSession();
  19.  
  20. emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
  21. em = emf.createEntityManager();
  22. logger.debug("** username:"+username);
  23. logger.debug("** password:"+password);
  24.  
  25. Query q = em.createNamedQuery("users.byUnPass");
  26. q.setParameter("username", username);
  27. q.setParameter("password", password);
  28. AbstractUser user;
  29.  
  30. try{
  31. user = (AbstractUser) q.getSingleResult();
  32. }catch(javax.persistence.NoResultException e){
  33. user = new AbstractUser();
  34. }
  35.  
  36. return user;
  37. }
Add Comment
Please, Sign In to add comment