String hql = "FROM User WHERE username = :username AND password = :password";List<User>list = session.createQuery(hql).setString("username", username).setString("password", password).list();list内如果有记录则登录成功,如果没有记录则登录失败。