@SuppressWarnings("unchecked")
public QuestionTag loadOrCreateTagByName(String name)
{
Query query = getEntityManager().createQuery("select t from QuestionTag t where t.tag = ?1");
query.setParameter(1, name);
QuestionTag tag = null;
try{
List<QuestionTag> tags = (List<QuestionTag>)query.getResultList();
if (tags==null || tags.isEmpty())
{
tag = new QuestionTag();
tag.setTag(name);
persist(tag);
}
else
{
tag = tags.get(0);