Java – how to enable batch insert in Hibernate?

Using hibernate, when I try to enable batch insert

<property name="jdbc.batch_size">50</property>

I get the following output:

[...] cfg.SettingsFactory INFO  - JDBC batch updates for versioned data: disabled
 [...] cfg.SettingsFactory INFO  - Order sql inserts for batching: disabled

Then this:

[...] jdbc.AbstractBatcher DEBUG - Executing batch size: 1

Never exceed batch: 1 Basic

I missed a setting?

Solution

To enable batching for both insert and update statements, you need to set all of the following hibernate properties:

<property name="hibernate.jdbc.batch_size">30</property>
<property name="hibernate.order_inserts">true</property>
<property name="hibernate.order_updates">true</property>
<property name="hibernate.jdbc.batch_versioned_data">true</property>

If you can use sequence <, you should not use identity generator because it disables batch fetching

If you cannot use sequence (e.g. MySQL), try using a separate mechanism to enable batch insertion (e.g. jooq), rather than using a table generator that does not scale and has a high performance loss

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>