I'm using this method in a Repository class and was wondering if
someone could do a quick sanity check on it:
@Transactional
public void persistList(List<BorderPoint> objectList) throws
RepositoryException {
EntityManager em = entityManagerFactory.createEntityManager();
try {
em.getTransaction().begin();
int i = 1;
for (BorderPoint bp : objectList) {
em.persist(bp);
if (i % 100 == 0) {
em.flush();
em.clear();
}
i++;
}
em.getTransaction().commit();
} catch (EntityExistsException ex) {
// need to log this somehow
//log.warning("persist() threw EntityExistsException: " +
ex.getMessage());
ex.printStackTrace();
throw new RepositoryException(ex);
}
catch (Exception e) {
e.printStackTrace();
} finally {
em.close();
}
}
I'm using it to persist data to a table that is quite large, and
performance seemed to degrade quickly when the table hit 3M rows.
Currently, I'm using MySQL with InnoDB tables.
Jason