How to use a JVM or database auto-generated UUID identifier with JPA and Hibernate

Introduction In this article, we are going to see how to use a UUID entity identifier that is auto-generated by Hibernate either in the JVM or using database-specific UUID functions. Our Post entity looks as follows: The Post entity has a UUID identifier and a title. Now, let’s see how we can map the Post entity so that the UUID identifier be auto-generated for us.

How to use database-specific or Hibernate-specific features without sacrificing portability

Introduction Like other non-functional requirements, portability is a feature. While portability is very important when working on an open-source framework that will be used in a large number of setups, for end systems, portability might not be needed at all. This article aims to explain that you don’t have to avoid database or framework-specific features if you want to achieve portability.

How to get the actual execution plan for an Oracle SQL query using Hibernate query hints

Introduction While answering this question on the Hibernate forum, I realized that it’s a good idea to write an article about getting the actual execution plan for an Oracle SQL query using Hibernate query hints feature.

How to map a JPA entity to a View or SQL query using Hibernate

Introduction In this article, you are going to learn how to map a JPA entity to the ResultSet of a SQL query using the @Subselect Hibernate-specific annotation.

How to cache non-existing entity fetch results with JPA and Hibernate

Introduction Sergey Chupov asked me a very good question on Twitter: https://twitter.com/scadgek/status/946838214744203269 In this article, I’m going to show you how to cache null results when using JPA and Hibernate.

JPA Criteria API Bulk Update and Delete

Introduction JPA Criteria API bulk update delete is a great feature that allows you to build bulk update and delete queries using the JPA 2.1 Criteria API support via CriteriaUpdate and CriteriaDelete. Because one of our community members asked me on the Hibernate forum about this topic, I decided it is a good opportunity to write about this lesser-known JPA Criteria API feature.

How to map a JSON collection using JPA and Hibernate

Introduction The open-source Hypersistence Utils project allows you to map Java objects or Jackson JsonNode as JPA or Hibernate entity properties, and, thanks to our awesome contributors, we have added support for storing type-safe JSON collections. In this article, you are going to see how to achieve this goal.

How to bootstrap JPA programmatically without the persistence.xml configuration file

Introduction One of my Twitter followers asked me if there is any documentation for bootstrapping JPA programmatically so that we can replace the persistence.xml configuration file with a Java configuration: Previously, I wrote an article about bootstrapping Hibernate without the persistence.xml, but that solution was based on the Hibernate-specific EntityManagerFactoryBuilderImpl. In this article, I’m going to give you a solution that works with any JPA provider since it’s based on standard Java Persistence API.

How to order entity subclasses by their class type using JPA and Hibernate

Introduction In this article, we are going to see how to order entity subclasses when executing a JPA query with Hibernate.

How to map a JPA @ManyToOne relationship to a SQL query using the Hibernate @JoinFormula annotation

Introduction Someone asked me to answer the following StackOverflow question, and, because the question is very interesting from an SQL perspective, I decided to turn the answer it into a blog post. In this article, we are going to see how to map a JPA @ManyToOne association to the result of a SQL query using the Hibernate-specific @JoinFormula annotation.