public User findUserByKey(String key) {
        Session session =null;
        User user;
        try {
            session= HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            Criteria criteria = session.createCriteria(User.class);
            user=(User)criteria.add(Restrictions.eq("key", key)).uniqueResult();
            if(user!=null)
            {
                session.getTransaction().commit();
                return user;
            }
        } catch (Exception exception) {
        } finally {

            if(session!=null && session.isOpen())
            {
                session.close();
            }
        }
        return null;
    }