Fetching recursive associations with JPA and Hibernate

Introduction In this article, we are going to see how to fetch recursive associations when using JPA and Hibernate. Recursive table relationships are built using self-referencing Foreign Key columns so that a record in a table can reference another record in the very same table, therefore allowing us to represent hierarchical structures using the relational model.

JPA Association Fetching Validator

Introduction In this article, I’m going to show you how we can build a JPA Association Fetching Validator that asserts whether JPA and Hibernate associations are fetched using joins or secondary queries. While Hibernate does not provide built-in support for checking the entity association fetching behavior programmatically, the API is very flexible and allows us to customize it so that we can achieve this non-trivial requirement.

How to synchronize bidirectional entity associations with JPA and Hibernate

Introduction While answering this StackOverflow question, I realized that it’s a good idea to summarize how various bidirectional associations should be synchronized when using JPA and Hibernate. Therefore, in this article, you are going to learn how and also why you should always synchronize both sides of an entity relationship, no matter if it’s @OneToMany, @OneToOne or @ManyToMany.

Best way to map the JPA and Hibernate ManyToMany relationship

Introduction In this article, I’m going to show you the best way to map a ManyToMany association when using JPA and Hibernate. As simple as JPA annotations might be, it’s not always obvious how efficient they are behind the scenes.

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

Introduction While adding a @OneToMany relationship is very easy with JPA and Hibernate, knowing the right way to map such an association so that it generates very efficient SQL statements is definitely not a trivial thing to do. In a relational database system, a one-to-many association links two tables based on a Foreign Key column so that the child table record references the Primary Key of the parent table row. As straightforward as it might be in a relational database, when it comes to JPA, the one-to-many database association can be represented… Read More