Need to insert 100000 rows in mysql using hibernate in under 5 seconds

前端 未结 4 470
我寻月下人不归
我寻月下人不归 2021-01-30 23:38

I am trying to insert 100,000 rows in a MYSQL table under 5 seconds using Hibernate(JPA). I have tried every trick hibernate offers and still can not do better than 35 seconds.

4条回答
  •  清酒与你
    2021-01-31 00:09

    Another option to consider is StatelessSession:

    A command-oriented API for performing bulk operations against a database.

    A stateless session does not implement a first-level cache nor interact with any second-level cache, nor does it implement transactional write-behind or automatic dirty checking, nor do operations cascade to associated instances. Collections are ignored by a stateless session. Operations performed via a stateless session bypass Hibernate's event model and interceptors. Stateless sessions are vulnerable to data aliasing effects, due to the lack of a first-level cache.

    For certain kinds of transactions, a stateless session may perform slightly faster than a stateful session.

    Related discussion: Using StatelessSession for Batch processing

提交回复
热议问题