How to map the latest child of a parent entity using Hibernate @JoinFormula

Introduction Today, I stumbled upon a StackOverflow answer that I gave some time ago and realized that it deserves a post of its own. As previously explained, the @JoinFormula is a very awesome annotation which allows you to customize the way you join entities beyond JPA @JoinColumn capabilities.

How to map calculated properties with Hibernate @Generated annotation

Introduction As I explained in this previous article, you can map calculated properties using Hibernate @Formula, and the value is generated at query time. In this post, you’ll see how you can calculate an entity property at INSERT or UPDATE time.

The best way to map a Composite Primary Key with JPA and Hibernate

Introduction One of my readers asked me to help him map a Composite Primary Key using JPA and Hibernate. Because this is a recurrent question, I decided to write a blog post in which I describe this mapping is more detail.

The best way to map a @OneToOne relationship with JPA and Hibernate

Introduction There are many ways you can map a one-to-one relationship with Hibernate. In this post, I’m going to demonstrate which mapping is the most efficient one from a database perspective.

How to map JSON objects using generic Hibernate Types

Introduction Since not all relational database systems support JSON types, Hibernate does not come with a built-in JSON Type mapper. Traditionally, all custom types have been supplied via a UserType implementation. However, a UserType is not very developer-friendly so, in this post, I’m going to show how you can do a better job using AbstractSingleColumnStandardBasicType instead.