// Switch to the CategoryDAO class
CategoryDAO catDAO = new CategoryDAO(em);
//query = em.createQuery("SELECT c FROM Category c WHERE c.name = :cname");
//query.setParameter("cname", qcategory);
Category qcat;
try
{
//qcat = (Category) query.getSingleResult();
qcat = catDAO.find(qcategory);
} catch (NoResultException e)
{
qcat = new Category(qcategory);
Long newCatId = catDAO.create(qcat);
qcat.setId(newCatId);
}
//tx.begin();
//em.persist(qcat);
//tx.commit();
qcat = catDAO.update(qcat);