The best way to do batch processing with JPA and Hibernate

Introduction

Recently, on of my followers asked me to answer a question on Quora about batch processing, and, since the question was really interesting, I decided to turn it into a blog post.

In this article, you are going to find out what batch processing is, why do we use it, and how to use it properly with JPA and Hibernate.

Continue reading “The best way to do batch processing with JPA and Hibernate”

Advertisements

How to find which statement failed in a JDBC Batch Update

Introduction

Yesterday, my Danish friend, Flemming Harms, asked my a very interesting question related to when a JDBC batch update fails.

Basically, considering we are going to group several DML statements in a batch, we need a way to tell which statement is the cause of the failure. This post is going to answer this question in more detail.

Continue reading “How to find which statement failed in a JDBC Batch Update”

How to customize the JDBC batch size for each Persistence Context with Hibernate

Introduction

JDBC batching has a significant impact on reducing transaction response time. As previously explained, you can enable batching for INSERT, UPDATE and DELETE statements with just one configuration property:

<property name="hibernate.jdbc.batch_size" value="5"/>

However, this setting affects every Persistence Context, therefore every business use case inherits the same JDBC batch size. Although the hibernate.jdbc.batch_size configuration property is extremely useful, it would be great if we could customize the JDBC batch size on a per Persistence Context basis. This article demonstrates how easily you can accomplish this task.

Continue reading “How to customize the JDBC batch size for each Persistence Context with Hibernate”

ResultSet statement fetching with JDBC and Hibernate

Introduction

Now that I covered Hibernate batch support for INSERT, UPDATE and DELETE statements, it’s time to analyze SELECT statements result set batch fetching.

JDBC ResultSet fetching

The JDBC ResultSet offers a client-side Proxy cursor for fetching the current statement return data. When the statement gets executed, the result must be transferred from the database cursor to the client-side one. This operation can either be done at once or on demand.

Continue reading “ResultSet statement fetching with JDBC and Hibernate”