Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing hibernate batch size programmatically

Tags:

hibernate

Is possible to change hibernate.jdbc.batch_size programmatically? I understand hibernate.jdbc.batch_size is a application level parameter, wanted to know if I can use it specifically for certain HQL inserts and not others. I would change the code only for those HQL inserts

The big picture is that I need to introduce batch inserts to make the web application performant in some scenarios, but I do not want to jeopardize the normal inserts which work right now.

like image 461
user179056 Avatar asked Apr 28 '10 12:04

user179056


2 Answers

To my knowledge, you can't change the configuration settings of a SessionFactory at runtime (the settings are not exposed via the public API and are immutable).

In other words, I would use another SessionFactory (and set the hibernate.jdbc.batch_size property in the Configuration object used to build it) in the specific scenarios needing it.

like image 134
Pascal Thivent Avatar answered Oct 13 '22 05:10

Pascal Thivent


From this blog post:

Hibernate 5.2 adds support for customizing the JDBC batch size at the Persistence Context level

entityManager.unwrap(Session.class)
        .setJdbcBatchSize(10)
like image 33
cdalxndr Avatar answered Oct 13 '22 07:10

cdalxndr