em.getTransaction().begin();
em.persist(sequence);
em.getTransaction().commit();
} catch (Exception ex) {
if (findSequence(sequence.getSeqName()) != null) {
throw new PreexistingEntityException("Sequence " + sequence + " already exists.", ex);
}
throw ex;
} finally {
if (em != null) {