1
I’m trying to persist a ArrayList
of Entity
in JPA with the following for
:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("PU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(testCaseEntity);
em.persist(testTypeEntity);
for (TestPlanParamsSpringModel test : testPlan.getParams()) {
em.persist(test);
}
em.getTransaction().commit();
em.close();
emf.close();
Thus only the last Entity treated by for
is inserted in the bank, how do I insert all of them? I tried some solutions using em.flush()
and em.clear()
at the end of the loop but did not succeed.