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:

A beginner’s guide to database table relationships

Introduction In a relational database, a relationship is formed by correlating rows belonging to different tables. A table relationship is established when a child table defines a Foreign Key column that references the Primary Key column of its parent table. Every database table relationship is, therefore, built on top of Foreign Key columns, and there can be three table relationship types: one-to-many is the most common relationship, and it associates a row from a parent table to multiple rows in a child table. one-to-one requires the child table Primary Key to be… Read More

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.

A beginner’s guide to JPA and Hibernate Cascade Types

Introduction In this article, we are going to learn how the JPA and Hibernate Cascade Types work. JPA translates entity state transitions to database DML statements. Because it’s common to operate on entity graphs, JPA allows us to propagate entity state changes from Parents to Child entities. This behavior is configured through the CascadeType mappings.