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 - 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
-
-
-
-
-
-
-
(Locked)
Finding and updating an existing entity instance7m 12s
-
(Locked)
Attaching and detaching an entity instance4m 42s
-
(Locked)
Removing an entity instance2m 42s
-
Using the getReference() and refresh() methods5m 53s
-
(Locked)
Using composite keys on an entity8m 1s
-
(Locked)
Challenge: Art Class Management app, part 31m 29s
-
(Locked)
Solution: Art Class Management app, part 34m 8s
-
(Locked)
-
-
-
-