Hello,
I don't want autocommitting and so I just call this piece of code as soon as the entities need to be committed. This does a rollback if anything fails.
Code:
/**
* @param entityManager - EntityManager
*/
public static void commitEntityManager(EntityManager entityManager) {
synchronized (entityManager) {
EntityTransaction transaction = entityManager.getTransaction();
try {
transaction.begin();
transaction.commit();
} catch (Throwable e) {
LOGGER.error("commitEntityManager: " + e, e);
if (transaction != null && transaction.isActive()) {
transaction.rollback();
}
FacesHelper.addError("Aanpassing mislukt... probeer opnieuw ! [" + e + "]");
}
}
}
Hmmm, reread your post and I now see that you WANT the others to be inserted. Maybe just call the commit for each insert? Or probably better, use the advise of experienced poster Sanne :)