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.
One-to-one relationships - JPA Tutorial
From the course: Java Persistence with JPA and Hibernate
One-to-one relationships
- [Instructor] A one-to-one relationship simply means that one of something is linked with only one of another thing. For example, a person owns a dog and a dog is owned by a person. It is a relationship in which two entities are linked, where an instance of one entity is linked to only one instance of the other entity. Remember to run the MariaDB 06_01 SQS script before you follow along with this demo. Let's run it. In this library database, there are authors for books. So we have an author table as well. The author ID is a foreign key in the book table. Let's assume that all the books have been authored by a single author, so we can say that a given book has only one author. Also, if we have only one single book of that author in the library, we can say that there's only one book of that author. How can we map this one to one relationship between two entities in Hibernate? We already have the book Entity class. I've also created the author Entity class. In JP, relationships can be…
Contents
-
-
-
-
-
-
-
-
(Locked)
One-to-one relationships8m 13s
-
@OneToMany and @ManyToOne annotations in a relationship8m 8s
-
(Locked)
Many-to-many relationships7m 29s
-
(Locked)
Inheritance9m 40s
-
(Locked)
More inheritance strategies9m 25s
-
(Locked)
Composition relationship11m 6s
-
(Locked)
Challenge: Art Class Management app, part 41m 58s
-
(Locked)
Solution: Art Class Management app, part 44m 41s
-
(Locked)
-
-
-