How to persist a lot of entities (JPA)

后端 未结 4 1422
半阙折子戏
半阙折子戏 2020-12-16 12:44

I need to process a CSV file and for each record (line) persist an entity. Right now, I do it this way:

while ((line = reader.readNext()) != null) {
    Enti         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-16 13:27

    I think one common way to do this is with transactions. If you begin a new transaction and then persist a large number of objects, they won't actually be inserted into the DB until you commit the transaction. This can gain you some efficiencies if you have a large number of items to commit.

    Check out EntityManager.getTransaction

提交回复
热议问题