user182944
user182944

Reputation: 8067

Setting Batch size in configuration

I am using hibernate 3.2.5. What is the exact use/meaning of the statement hibernate.jdbc.batch_size in a hibernate configuration file?

From the documentation, I can see that we need to add this line in the configuration for batch processing otherwise, batch processing is disabled by default. Apart from that, what is the specific reason for assigning the above line to a number?

It is not like if I assign it to 30(suppose) then my batch will be able to insert/update/delete at max 30 rows, I tested this thing in my local. Then what is the use of the number we assign for this?

Please let me know about this.

Regards,

Upvotes: 2

Views: 4403

Answers (2)

Anand
Anand

Reputation: 21320

JDBC batch updates allow sending multiple update queries in a single batch to the database. It reduces the number of network calls. You can view it as uploading an uncompressed zip containing 20 files instead of sending 20 files individually.

Upvotes: 2

Yogendra Singh
Yogendra Singh

Reputation: 34367

Just to explain: Say for example, you have one entity Parent, which has one-to-many relationship with another entity Child with initialization as lazy.

By defining hibernate.jdbc.batch_size = 30, you mean that when you try getting the Child entities from Parent entity, it will load them in batch size of 30 i.e. 30 Child objects at a time, if its available 30 or more otherwise available number of objects.

e.g. If Parent has 100 Child objects lazily loaded, now you are iterating the Child objects, it will trigger 4 queries in the back-end to load Child object in chunk of 30, 30, 30 and 10.

Hope this help!

Upvotes: 3

Related Questions