Modeling self-referencing associations with Hibernate
|

Modeling self-referencing associations with Hibernate

When you model a hierarchical data structure, you often have to use self-referencing associations. Both ends of these associations are of the same type. In other words, the entity object on which the association is defined and the one the association references are of the same type. In your database, you model that using a…

Ternary Associations – Modelling Associations between 3 Entities

Ternary Associations – Modelling Associations between 3 Entities

An association between 3 entities is called a ternary association. A typical example is an association between an employee, the project they are working on, and their role in that project. If the role is a complex object, you might decide to model this as 3 entity classes. The association between them is the interesting…

Your 2 best options to fix Hibernate’s MultipleBagFetchException

Your 2 best options to fix Hibernate’s MultipleBagFetchException

You probably learned that you should use FetchType.LAZY for all of your associations. It ensures that Hibernate initializes an association when you use it and doesn’t spend any time getting data you don’t need. Unfortunately, this introduces a new issue. You now need to use a JOIN FETCH clause or an EntityGraph to fetch the…