Skip to content

Instantly share code, notes, and snippets.

@jerolba
Last active August 21, 2018 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerolba/6a7d2b455943c4b3cf91f172c3e06753 to your computer and use it in GitHub Desktop.
Save jerolba/6a7d2b455943c4b3cf91f172c3e06753 to your computer and use it in GitHub Desktop.
EntityTransaction tx = entityManager.getTransaction();
Iterator<TripEntityJpa> iterator = trips.iterator();
tx.begin();
int cont = 0;
int idSeq = 1;
while (iterator.hasNext()) {
TripEntityJpa trip = iterator.next();
trip.setId(idSeq++);
entityManager.persist(trip);
cont++;
if (cont % batchSize == 0) {
entityManager.flush();
entityManager.clear();
tx.commit();
tx.begin();
}
}
tx.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment