MySQL rewriteBatchedStatements configuration property
Introduction In this article, we are going to see how MySQL rewriteBatchedStatements works when using JDBC, JPA, or Hibernate. I first researched this MySQL configuration property when I was writing the batching chapter of my High-Performance Java Persistence book, and, back then, I discovered that this setting allows batching plain Statement by rewriting the SQL string that is sent to the database. However, the MySQL 6 Connector/J documentation mentioned that: for prepared statements, server-side prepared statements can not currently take advantage of this rewrite option So, for a long time, I wrongly… Read More
PostgreSQL reWriteBatchedInserts configuration property
Introduction The PostgreSQL JDBC Driver has been adding a lot of very useful optimizations, and one of the lesser-known ones is the reWriteBatchedInserts configuration property. In this article, you will see how the reWriteBatchedInserts JDBC configuration property works in PostgreSQL, and how it allows you to rewrite INSERT statements into a multi-VALUE INSERT.
PostgreSQL SERIAL or IDENTITY column and Hibernate IDENTITY generator
Introduction When using PostgreSQL, it’s tempting to use a SERIAL or BIGSERIAL column type to auto-increment Primary Keys. PostgreSQL 10 also added support for IDENTITY, which behaves in the same way as the legacy SERIAL or BIGSERIAL type. This article will show you that SERIAL, BIGSERIAL, and IDENTITY are not a very good idea when using JPA and Hibernate.
How to optimize the merge operation using update while batching with JPA and Hibernate
Introduction One of my readers has recently asked me about optimizing the merge entity state transition, and, because this is a great question, I decided to turn it into a blog post. In this article, you are going to see a shortcoming of the merge entity state transition and how you can deal with it using Hibernate.
The best way to do batch processing with JPA and Hibernate
Introduction Recently, one 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.
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.
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: 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.
JDBC Statement fetchSize property
Introduction In this article, we are going to see how the JDBC Statement fetchSize property works when using Oracle, SQL Server, PostgreSQL, or MySQL. JDBC ResultSet fetching The JDBC ResultSet offers a client-side 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.
How to batch DELETE statements with Hibernate
Introduction In my previous post, I explained the Hibernate configurations required for batching INSERT and UPDATE statements. This post will continue this topic with DELETE statements batching. Domain model entities We’ll start with the following entity model:
How to batch INSERT and UPDATE statements with Hibernate
Introduction JDBC has long been offering support for DML statement batching. By default, all statements are sent one after the other, each one in a separate network round-trip. Batching allows us to send multiple statements in one-shot, saving unnecessary socket stream flushing. Hibernate hides the database statements behind a transactional write-behind abstraction layer. An intermediate layer allows us to hide the JDBC batching semantics from the persistence layer logic. This way, we can change the JDBC batching strategy without altering the data access code. Configuring Hibernate to support JDBC batching is not… Read More