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

2. Entities

Anghel Leonard1 
(1)
Banesti, Romania
 

Item 13: How to Adopt a Fluent API Style in Entities

Consider the Author and Book entities, which are involved in a bidirectional lazy @OneToMany association , as shown in Figure 2-1.
../images/487471_1_En_2_Chapter/487471_1_En_2_Fig1_HTML.jpg
Figure 2-1

The @OneToMany table relationship

Usually, you can create an Author with Books as follows (e.g., one author with two books):
Author author = new Author();
author.setName("Joana Nimar");
author.setAge(34);
author.setGenre("History");
Book book1 = new Book();
book1.setTitle("A History of Ancient Prague");
book1.setIsbn("001-JN"); ...

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.