Transactions, Spring.
entityManager = entityManagerFactory.createEntityManager(); try { entityManager.getTransaction().begin(); entityManager.persist(firstEntity); entityManager.persist(secondEntity); entityManager.getTransaction().commit(); } catch (Exception e) { entityManager.getTransaction().rollback(); } Here,