From the course: Java Persistence API (JPA): 1 The Basics
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Mapping strategies overview - Java Tutorial
From the course: Java Persistence API (JPA): 1 The Basics
Mapping strategies overview
- [Instructor] @JoinTable and @JoinColumn are two very useful annotations when mapping entity relationships but when would you want to use one over the other? Let's learn the differences between @JoinColumn and @JoinTable and the pros and cons of each strategy. We were briefly introduced to @JoinColumn previously. Let's explore it further. @JoinColumn is like a foreign key relationship. The primary key of the associated object is stored as a column in the owning entities table. In this case the associated application is represented by application ID in the ticket class, which maps to the primary key of the Application class. This is modeled in our code like so. Notice on our application object we add the @JoinColumn annotation and pass in Application ID as the column or field to Join on. There is another way to model relationships between entities and it's called Join Table represented by the @JoinTable annotation. @JoinTable uses a third table to associate the relationship between…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.