//Root<Category> categoryRoot = cq.from(Category.class);
//cq.where(cb.equal(categoryRoot.get("name"),
// txtCategory.getText().trim()));
//TypedQuery<Category> categoryQuery = em.createQuery(cq);
CategoryDAO catDAO = new CategoryDAO(emf.createEntityManager());
Category queryCat;
try
{
//queryCat = categoryQuery.getSingleResult();
queryCat = catDAO.find(txtCategory.getText().trim());
LOGGER.info("Category already exists in database: "
+ queryCat.getName());
} catch (NoResultException ex)
{
queryCat = new Category(txtCategory.getText().trim());
//tx.begin();
//em.persist(queryCat);
//tx.commit();
Long newCatId = catDAO.create(queryCat);
queryCat.setId(newCatId);
LOGGER.info("Added Category: " + queryCat.getName());
}
question.setCategory(queryCat);
if (catDAO.isOpen())
{
catDAO.closeConnection();