Hibernate Relationship Mapping/Speed up batch inserts

后端 未结 2 1164
星月不相逢
星月不相逢 2020-12-29 15:43

I have 5 MySQL InnoDB tables: Test,InputInvoice,InputLine,OutputInvoice,OutputLine and each is mapped and functioning in Hibernate. I have played with using Sta

2条回答
  •  攒了一身酷
    2020-12-29 16:21

    The final solution for me was to use voetsjoeba's response as a jumping off point. My hibernate config uses the following options:

    hibernate.order_inserts = true
    hibernate.order_updates = true
    
    • I changed from using Session to StatelessSession

    • Re-ordered the Java code to process all the elements in a batch a table at a time. So all of table x, then table y, etc.

    • Removed the from each class. Java now creates it and assigns it to the object

    • Created logic that allowed me to determine if just an id was being set and not write 'empty' lines to the database

    • Finally, I turned on dynamic-insert for my classes in their hibernate definitions like so:

提交回复
热议问题