Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public <R> R doInTransaction(final Function<EntityManager, R> whatToDo) {
- final EntityManager em = emf.createEntityManager();
- final R result;
- try {
- try {
- em.getTransaction().begin();
- result = whatToDo.apply(em);
- em.getTransaction().commit();
- } finally {
- if (em.getTransaction().isActive()) {
- em.getTransaction().rollback();
- }
- }
- } finally {
- em.close();
- }
- return result;
- }
- em.unwrap(Session.class).doWork(connection -> {
- // stored procedures are called here directly over JDBC
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement