Skip to content

Instantly share code, notes, and snippets.

@jerolba
Created August 20, 2018 22:06
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/30c63eafec74bc9b4f77a5d78d61262a to your computer and use it in GitHub Desktop.
Save jerolba/30c63eafec74bc9b4f77a5d78d61262a to your computer and use it in GitHub Desktop.
A register each time in transactions of 1000 elements
EntityTransaction tx = entityManager.getTransaction();
Iterator<TripEntity> iterator = trips.iterator();
tx.begin();
int cont = 0;
while (iterator.hasNext()) {
entityManager.persist(iterator.next());
cont++;
if (cont % batchSize == 0) {
tx.commit();
tx.begin();
}
}
tx.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment