我正在为数据库 mysql 使用 jpa eclipselink,我需要批量插入一个包含 6000 多个对象的列表。但是数据库中只插入了 215 行,没有抛出异常。
这是我的代码
private EntityManagerFactory emf = null;
private static final String PERSISTENCE_UNIT_NAME = "Cation";
private static EntityManagerFactory factory;
public EntityManager getEntityManager() {
return emf.createEntityManager();
}
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
try {
em.getTransaction().begin();
for (int i = 0; i < sgmlList.size(); i++) {
// Getting the object from the list by using loop
SGML sgml = sgmlList.get(i);
em.persist(sgml);
}
em.getTransaction().commit();
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("SGML imported successfully"));
} catch (Exception ex) {
} finally {
if (em != null) {
em.close();
}
}
谁能帮我解决这个问题。