I have class Login which has `userId`, `username` and `password`.

For a user to login I am checking `username` and `password` and geting `userId`.
If `userId` is not zero then it will lead to home page. I am trying to do this in hibernate. But my query is not working

```
public int userLogin(Login login)
        throws MySQLIntegrityConstraintViolationException, SQLException,
        Exception {

    Session session = HibernateUtil.getSessionFactory().openSession();
    int userId = 0;

    try {
            session.beginTransaction();
            String hql = "Select log.userId from Login log where log.userName=:userName 
            and log.password=:password";      
            System.out.println(hql);
            Query query = session.createQuery(hql);
            query.setParameter(":userName", login.getUserName());
            query.setParameter(":password", login.getPassword());
            List result = query.list();

            System.out.println("resultset:"+result);

            Iterator iterator = result.iterator();
            while(iterator.hasNext()){
                userId = (int) iterator.next();

        }
    } catch (HibernateException e) {
        if (session.getTransaction() != null) {
            session.getTransaction().rollback();
        }
    } finally {
        session.close();
    }

```