Hibernate HSQLDB ARRAY Type

Introduction As previously explained, although Hibernate does not support database ARRAY column types by default, you can easily implement a custom Hibernate ArrayType. While the previous solution worked on PostgreSQL, in this article, you are going to see that it is fairly easy to adapt it to HSQLDB.

How to install DB2 Express-C on Docker and set up the JDBC connection properties

Introduction While developing Hibernate, I need to test the code base against a plethora of relational database systems: Oracle, SQL Server, PostgreSQL, MySQL, MariaDB, Informix, and of course DB2. However, having all these databases installed on my system is far from ideal, so I rely a lot on Docker for this task. In this article, I’m going to show how easily you can install DB2 on Docker and set up the JDBC connection so that you can run Hibernate tests on DB2.

How to get started with CockroachDB

Introduction CockroachDB is a really interesting database system, getting the best of both RDBMS and NoSQL. It’s been developed by former Google developers, and it’s inspired by Google Spanner. However, unlike Google Spanner, which is offered as a service in Google Cloud, CockroachDB is an open-source database that can be installed on premise. Also, CockroackDB allows you to use the PostgreSQL drivers as opposed to Spanner which only supports the gRPC protocol. So, you can practically reuse all the frameworks that have emerged in the Java ecosystem like connection pools, monitoring proxies… Read More

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.

The print version of High-Performance Java Persistence

One year after I published the first part of the High-Performance Java Persistence, I managed to publish the print version of the book. The book is printed on demand using Amazon CreateSpace, and it looks like as follows.

A beginner’s guide to SQL injection and how you should prevent it

Introduction One of my readers asked me to answer the following StackOverflow question. Right from the start, I noticed that the entity query was constructed by concatenating strings, which can expose your application to SQL Injection attacks. Unfortunately, I’ve been seeing this problem over and over throughout my career, and not all developers are aware of the serious risk associated with SQL Injection. For this reason, this post is going to demonstrate what damage can SQL Injection do to your system.

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.

The best way to log SQL statements with JDBC, JPA or Hibernate

Introduction In this article, I’m going to show you the best way to log SQL statements when using either JDBC, JPA, or Hibernate. Whenever you are using a data access framework that auto-generates statements on your behalf, it is mandatory to log all statements to ensure their effectiveness, as well as to assert the possible performance implications.

High-Performance Java Persistence – Part One

The journey Four months, one week and two days and 114 pages; that’s how much it took to write the first part of the High-Performance Java Persistence book. As previously stated, the book is developed in an Agile fashion. Each part represents a milestone, which is accompanied by a release. This way, the readers can get access to the book content prior to finishing the whole book (which might take a year or so).

How does the MySQL JDBC driver handle prepared statements

Prepared statement types While researching for the Statement Caching chapter in my High-Performance Java Persistence book, I got the chance to compare how Oracle, SQL Server, PostgreSQL and MySQL handle prepare statements. Thanks to Jess Balint (MySQL JDBC driver contributor), who gave a wonderful answer on StackOverflow, I managed to get a better understanding of how MySQL handles prepared statements from a database performance point of view.