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.
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"); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.