The best way to use the JPA OneToOne optional attribute

Introduction In this article, we are going to see what is the best way we can use OneToOne optional attribute so that we can avoid N+1 query issues.

The best way to map multiple entities on the same table

Introduction In this article, we are going to see what is the best way to map multiple entities on the same table. There are several advantages to mapping multiple entities on the same database table: To avoid loading large columns (e.g., JSON) To avoid N+1 query issues for bidirectional @OneToOne associations Before we start investigating the best way to map multiple entities on the same table, if you wonder why you even need to use one-to-one table relationships, then check out this article first.

The best way to use one-to-one table relationships

Introduction In this article, we are going to see what is the best way to use one-to-one table relationships. I decided to write this article after reading this Tweet:

How to change the @OneToOne shared primary key column name with JPA and Hibernate

Introduction In this article, we are going to see how you can change the @OneToOne shared primary key column name when using JPA and Hibernate. This has been a recurrent theme when answering questions about Hibernate or during my High-Performance Java Persistence training. As previously explained, the one-to-one database table relationship requires the Primary Key to be shared among the parent and the child tables. Unfortunately, just adding the JPA @OneToOne annotation in the child entity does not render a true one-to-one table relationship since a separate Foreign Key column will be… Read More

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

Introduction In this article, we are going to learn the best way to map a OneToOne association with JPA and Hibernate. While there are many ways you can map a one-to-one relationship with Hibernate, I’m going to demonstrate which mapping is the most efficient one from a database perspective.