© Anghel Leonard 2020
A. LeonardSpring Boot Persistence Best Practiceshttps://doi.org/10.1007/978-1-4842-5626-8_5

5. Collections

Anghel Leonard1 
Banesti, Romania

Item 56: How to JOIN FETCH an @ElementCollection Collection

Especially when defining a unidirectional one-to-many association to a Basic type (e.g., String) or Embeddable type, JPA has a simple solution in the form of @ElementCollection. These types are mapped in a separate table that can be customized via @CollectionTable . Let’s assume that an online bookstore shopping cart is mapped via the ShoppingCart entity and the embeddable Book is mapped via @ElementCollection, as shown in Figure 5-1.
Figure 5-1

The @ElementCollection table relationship

The relevant part is the @ElementCollection ...

Get Spring Boot Persistence Best Practices: Optimize Java Persistence Performance in Spring Boot Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.