Hibernate batch insert, batch update

主宰稳场 提交于 2019-12-06 16:26:16

问题


I have dao which basically inserts a record into a table using hibernate, this dao is marked by @Transactional annotation with propogation-NESTED, and I have service which makes some other stuff and then invokes my dao. My service is also annotated with @Transactional with propagation-REQUIRED.

I call service in a loop. Does my inserts on my dao works in batch or one by one? How can I be sure that they work in batch? Does hibernateTransaction manager manage batch inserts?

I am using Oracle DB.


回答1:


I have set following property and my performance increased;

hibernate.jdbc.batch_size=50



回答2:


I am no Hibernate expert but I remember adding a property to log out the sql statements.

     SessionFactory sf = new Configuration()
       .setProperty("hibernate.show_sql", "true")

This should show what sql is being produced after each execution of your method




回答3:


It will not go in a batch, have a look at Hibernate Doc.




回答4:


To track if hibernate uses batches you may create logger for org.hibernate.jdbc.AbstractBatcher it will log batcher...



来源:https://stackoverflow.com/questions/8972853/hibernate-batch-insert-batch-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!