What is the use of Hibernate batch processing

后端 未结 3 600
后悔当初
后悔当初 2021-01-07 08:05

I am new to hibernate i have doubt in hibernate batch processing, i read some tutorial for hibernate batch processing they said

Session session = SessionFact         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 08:29

    No. Don't initialize the session in the for loop; every time you start a new session you're starting a new batch (so you have a batch size of one your way, that is it is non-batching). Also, it would be much slower your way. That is why the first example has

    if( i % 50 == 0 ) { 
      //flush a batch of inserts and release memory:
      session.flush();
      session.clear();
    }
    

    that is what "flush a batch of inserts and release memory" was for.

提交回复
热议问题