问题
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