Bulk update optimistic locking with JPA and Hibernate

Introduction In this article, we are going to see how we can adjust a bulk update statement so that it takes optimistic locking into consideration. While Hibernate has been supporting versioned HQL queries for a very long time, it’s actually very easy to achieve this goal even with standard JPQL or JPA Criteria API.

The best way to fix the Hibernate MultipleBagFetchException

Introduction If you’ve been using Hibernate for some time, there is a good chance you bumped into a MultipleBagFetchException issue: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags In this article, we are going to see the reason Hibernate throws the MultipleBagFetchException as well as the best way to solve this issue.

The best way to fetch multiple entities by id using JPA and Hibernate

Introduction In this article, we are going to see how we can load multiple entities by id at once when using JPA and Hibernate. Loading multiple entities by their identifier is a very common requirement when using JPA and Hibernate. Hence, we are going to see how we can optimize the underlying SQL query execution.

How to map SQL Server JSON columns using JPA and Hibernate

Introduction In this article, we are going to see how easy it is to map an SQL Server JSON column when using the Hibernate Types project. Not only that the hibernate-types project supports JSON column types for PostgreSQL and MySQL and Oracle, but, as you will see in this article, the JsonStringType works just fine when using Microsoft SQL Server.

How to map Oracle JSON columns using JPA and Hibernate

Introduction In this article, we are going to see how to map the Oracle JSON column storage types when using JPA and Hibernate. My hibernate-types project has long been supporting JSON for PostgreSQL and MySQL. However, while developing my new and awesome SQL Master Class training, I realized that the current implementation does not handle Oracle JSON column types properly. Luckily, the fix was easy and starting with the 2.7.0 version you can now persist and fetch JSON attributes on Oracle using JPA and Hibernate.

How to write a compact DTO projection query with JPA

Introduction In this article, we are going to see how we can write the best DTO projection JPQL query by omitting the package name when using JPA, Hibernate, and Spring. As I already explained, DTO projections are the most efficient way of fetching data when using JPA and Hibernate.

How to map multiple JPA entities to one database table with Hibernate

Introduction In this article, we are going to see how we can map multiple JPA entities to one table with Hibernate. Using multiple entities can speed up both read and write operations. This question has been a recurring theme on StackOverflow, so I decided to explain the advantages of mapping multiple JPA entities to the same database table.

How to write JPA Criteria API queries using Codota

Introduction Writing JPA Criteria API queries is not very easy. The Codota IDE plugin can guide you on how to write such queries, which greatly simplifies the process. In this article, we are going to see how Codota works and how it can help you discover a given API.

Query timeout with JPA and Hibernate

Introduction In this article, we are going to see what is the best way to set up the query timeout interval with JPA and Hibernate. Setting the query timeout allows you to cancel slow-running queries that would, otherwise, put pressure on database resources.

A beginner’s guide to JPA and Hibernate query hints

Introduction In this article, we are going to see what JPA query hints are, and get to know all the query hints supported by Hibernate. Understanding the Hibernate query hints is very important when developing a non-trivial enterprise application since they allow you to customize the way queries are executed by Hibernate.