Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public AbstractUser login(String username, String password){
- //Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
- //SessionFactory sessionFactory= cfg.buildSessionFactory();
- SessionFactory sessionFactory;
- sessionFactory = new AnnotationConfiguration()
- .addAnnotatedClass(AbstractUser.class)
- .addAnnotatedClass(CourseSession.class)
- .addAnnotatedClass(Course.class)
- .addAnnotatedClass(Message.class)
- .addAnnotatedClass(Material.class)
- .addAnnotatedClass(TopicSession.class)
- .addAnnotatedClass(Step.class)
- .addAnnotatedClass(Section.class)
- .addAnnotatedClass(Topic.class)
- .addAnnotatedClass(Subtopic.class)
- .configure("hibernate.cfg.xml")
- .buildSessionFactory();
- sessionFactory.openSession();
- emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
- em = emf.createEntityManager();
- logger.debug("** username:"+username);
- logger.debug("** password:"+password);
- Query q = em.createNamedQuery("users.byUnPass");
- q.setParameter("username", username);
- q.setParameter("password", password);
- AbstractUser user;
- try{
- user = (AbstractUser) q.getSingleResult();
- }catch(javax.persistence.NoResultException e){
- user = new AbstractUser();
- }
- return user;
- }
Add Comment
Please, Sign In to add comment