From the course: Java Persistence API (JPA): 1 The Basics

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Mapping associations overview

Mapping associations overview - Java Tutorial

From the course: Java Persistence API (JPA): 1 The Basics

Start my 1-month free trial

Mapping associations overview

- [Instructor] Let's learn about the four different cardinalities when mapping entity relationships in JPA. The cardinality between two relationships can be OneToOne, OneToMany, ManyToOne, or ManyToMany. Cardinality is also known as multiplicity, and captures the aspects of how many entities exist on each side of the relationship. JPA has four annotations to map unidirectional and bidirectional relationships. With @OneToOne annotation, each entity instance is related to a single instance of another entity. With @OneToMany, an entity instance can be related to multiple instances of the other entities. @ManyToOne multiple instances of an entity can be related to a single instance of the other entity. All of our examples up to this point have been ManyToOne. @ManyToMany, the entity instances can be related to multiple instances of each other. With configuration by exception, meaning if we used JPA's default mapping strategy, the OneToOne and ManyToOne relationships will be mapped using a…

Contents