From the course: Java Persistence with JPA and Hibernate

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Composition relationship

Composition relationship

- [Instructor] You may already know that the composition relationship in OOP, models has a whole part association, that is one class referring to another class, which is supposed to be the part, using an instance variable. It is generally recommended that composition should be used instead of inheritance wherever possible in plain Java classes. This is also valid for entity classes. At the same time, when working with entities, you should always keep in mind that your classes are mapped to database tables. Jakarta Persistence and Hibernate supports two ways to implement composition, association mapping and embedabbles. Association mapping is the most natural way of using composition in ORM. This is because the way it's done is similar in both the OO model and the relational model. Let's take this example. To implement composition using association mapping, start by running the mariadb-06_06.sql script. Let's run it. In the library, there are resources belonging to different fields…

Contents