Created
August 20, 2018 22:11
-
-
Save jerolba/d9c1953a8c9faef7b265ae9b20d9baa6 to your computer and use it in GitHub Desktop.
Transactions of 1000 elements with flush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
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