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.

Using composite keys on an entity

Using composite keys on an entity - JPA Tutorial

From the course: Java Persistence with JPA and Hibernate

Using composite keys on an entity

- In an earlier video, you saw how to define the primary key of an entity. But the primary key was defined based on a single field of the entity. In the database, the primary key was a single column of the table, like the book_id in the book table. There could be times where your database table has a primary key composed of more than one column, because using a single column, a record cannot be made unique. This is known as a composite key or a composed primary key. How is it possible to define such a primary key in the application or in other words, in your entity class? I'm in the 05_05 E branch to show you through the steps, but if you'd like to follow along, I've created an empty branch 05_05 B for you. Before you start, you also need to run the MariaDB-init.sql script if you haven't done so. And MariaDB-05_05.sql script that can be found in the 05_05 B branch. So I'm going to run this one MariaDB-05_05.sql script. Once you run it, there's a table named Book_type created in the…

Contents