Boa noite, Pessoal
Eu tenho um método onde realizo o save da entidade e gostaria de retornar o que foi salvo. A duvida é dessa forma é melhor jeito?
try {
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(entity);
tx.commit();
return entity;
} catch (RuntimeException e) {
em.getTransaction().rollback();
return null;
} finally {
if (em != null && em.isOpen()) {
em.close();
}
}
Abs