Last active
August 21, 2018 21:24
-
-
Save jerolba/6a7d2b455943c4b3cf91f172c3e06753 to your computer and use it in GitHub Desktop.
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<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