Multiplicities are of the following types:
One-to-one mapping defines a single-valued association to another entity that has one-to-one multiplicity. This relationship mapping use the @OneToOne
annotation on the corresponding persistent property or field.
Example: Vehicle
and ParkingPlace
entities.
An entity instance can be related to multiple instances of the other entities.
One-to-many relationships use the @OneToMany
annotation on the corresponding persistent property or field.
The mappedBy
element is needed to refer to the attribute annotated by ManyToOne in the corresponding entity:
@OneToMany(mappedBy="attribute")
A one-to-many association needs to map the collection of entities.
A many-to-one mapping is defined by annotating the attribute in the source entity (the attribute that refers to the target entity) with the @ManyToOne
annotation.
A @JoinColumn(name="FK_name")
annotation discribes a foreing key of a relationship.
The entity instances can be related to multiple instances of each other.
Many-to-many relationships use the @ManyToMany
annotation on the corresponding persistent property or field.
We must use a third table to associate the two entity types (join table).