I have a jpa code that genrates players (10000) and for each player 100 game and inserts them in a db but it's so slow i've tried using btch writing where i've set the btch size and then used the flush / clean methods but that hasn't changed much
List<Player> players = new ArrayList<>();
Random rd = new Random();
@Override
public void createMassData() {
EntityManager em = lab02EntityManager.getEntityManager();
EntityTransaction tx = em.getTransaction();
List<Category> allCategories =
lab02EntityManager
.getEntityManager()
.createQuery("select c from Category c")
.getResultList();
players = createPlayers();
tx.begin();
int trans = 1000;
int index=0;
for (Player player : players) {
em.persist(player);
index++;
for (int i = 0; i < 10; i++) {
em.persist(playGame(player, allCategories));
index++; }
if (index > trans){
index=0;
em.flush();
em.clear();
}
}
System.out.println("created ..");
tx.commit();
}