public static boolean buyProduct(Integer id) {
        Session session = HibernateUtil.getSessionFactory().openSession();

        Query query = session.createQuery("from Product where id = :id");
        query.setParameter("id", id);
        Product product = (Product)query.uniqueResult();
        if(product!=null && product.getAmount()>0) {
            product.setAmount(product.getAmount()-1);
            Transaction transaction = session.beginTransaction();
            session.update(product);
            transaction.commit();
            return true;
        }
        return false;
    }