Skip to content

Instantly share code, notes, and snippets.

@ricardojob
Created November 7, 2014 03:49
Show Gist options
  • Save ricardojob/89c9020b3946591a50f7 to your computer and use it in GitHub Desktop.
Save ricardojob/89c9020b3946591a50f7 to your computer and use it in GitHub Desktop.
@PersistenceContext(unitName = "nomeDaUnidade")
private EntityManager em;
@Resource
private javax.transaction.UserTransaction utx;
public void persist(Object object) {
try {
utx.begin();
em.persist(object);
utx.commit();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
throw new RuntimeException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment