From the course: Java Persistence with JPA

Unlock the full course today

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

Demo: Annotating a one-to-one relationship

Demo: Annotating a one-to-one relationship - Java Tutorial

From the course: Java Persistence with JPA

Demo: Annotating a one-to-one relationship

- [Instructor] Now let's open the code to see the one-to-one relationship modeled in Java using the at one-to-one annotation. I'm navigated to the employee class in IntelliJ. Let's scroll down to line 36 and notice here, you'll see the OneToOne annotation with mappedBy. mappedBy signals hibernate to use the EmployeeProfile's employee field to map the profile to an employee. Now, let's navigate to EmployeeProfile, and let's scroll down to line 26. Here on line 26, notice, there's also a OneToOne annotation on this employee field. This is how the mapping works from the Employee object. This employee field in EmployeeProfile makes the mapping happen. Now, let's see how this mapping is modeled in the Postgres database. Let's navigate to pgAdmin. Remember, the employee entity is mapped to a table name employee. So let's see what's in our Employee's database. We have one entity, Mary Doe, and let's make a note of her…

Contents