JPA - EntityManager.setFlushMode Examples

Code Snippets JPA JAVA EE 

    private static void persistEntity(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT);
List<Employee> employeeList = getNewEmployees();

em.getTransaction().begin();
for (Employee employee : employeeList) {
em.persist(employee);
}
em.flush();
showPersistedITEmployees(em);
em.getTransaction().commit();
em.close();
}
Original Post




    private static void persistEntity(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT);
List<Employee> employeeList = getNewEmployees();

em.getTransaction().begin();
for (Employee employee : employeeList) {
em.persist(employee);
}
// em.flush();
showPersistedITEmployees(em);
em.getTransaction().commit();
em.close();
}
Original Post




See Also