: Anghel Leonard
: Spring Boot Persistence Best Practices Optimize Java Persistence Performance in Spring Boot Applications
: Apress
: 9781484256268
: 1
: CHF 70.80
:
: Programmiersprachen
: English
: 1043
: Wasserzeichen/DRM
: PC/MAC/eReader/Tablet
: PDF

This book is a collection of developer code recipes and best practices for persisting data using Spring, particularly Spring Boot. The book is structured around practical recipes, where each recipe discusses a performance case or performance-related case, and almost every recipe has one or more applications. Mainly, when we try to accomplish something (e.g., read some data from the database), there are several approaches to do it, and, in order to choose the best way, you have to know the implied trades-off from a performance perspective. You'll see that in the end, all these penalties slow down the application. Besides presenting the arguments that favor a certain choice, the application is written in Spring Boot style which is quite different than plain Hibernate.

 

&nb p;

 

After reading and using this book, you'll have the fundamentals to apply these persistence solutions into your own mission-critical enterprise Java applications that you build using Spring.

 

What You Will Learn

 

 

  • Shape *-to-many associations for best performances
  • Effectiv ly exploit Spring Projections (DTO)
  • Learn best practices for batching inserts, updates and deletes
  • Effectively fetch parent and association in a single SELECT
  • Learn how to inspect Persistent Context content
  • Dissect pagination techniques (offset and keyset)
  • Handle queries, locking, schemas, Hibernate types, and more

 

 

&nb p;

 

 < p>

 

Who This Book Is For 

Any Spring and Spring Boot developer that wants to squeeze the persistence layer performances.


Anghel Leonard is a Chief Technology Strategist with 20+ years of experience in the Java ecosystem. In daily work, he is focused on architecting and developing Java distributed applications that empower robust architectures, clean code, and high-performance. Also passionate about coaching, mentoring and technical leadership. He is the author of several books, videos and dozens of articles related to Java technologies.

<
Table of Contents5
About the Author23
About the Technical Reviewer24
Introduction25
Chapter 1: Associations29
Item 1: How to Effectively Shape the @OneToMany Association29
Always Cascade from Parent-Side to Child-Side30
Don’t Forget to Set mappedBy on the Parent-Side30
Set orphanRemoval on the Parent-Side31
Keep Both Sides of the Association in Sync31
Override equals() and hashCode()32
Use Lazy Fetching on Both Sides of the Association33
Pay Attention to How toString() Is Overridden33
Use @JoinColumn to Specify the Join Column Name33
Author and Book Samples34
Item 2: Why You Should Avoid the  Unidirectional @OneToMany Association36
Regular Unidirectional @OneToMany38
Persisting an Author and Their Books38
Persisting a New Book of an Existing Author40
Deleting the Last book41
Deleting the First Book42
Using @OrderColumn43
Persist the Author and Books44
Persist a New Book of an Existing Author45
Delete the Last Book45
Delete the First Book46
Using @JoinColumn47
Persist the Author and Books47
Persist a New Book of an Existing Author48
Delete the Last Book49
Delete the First Book49
Item 3: How Efficient Is the  Unidirectional @ManyToOne50
Adding a New Book to a Certain Author52
Fetching All Books of an Author54
Paging the Books of an Author55
Fetching All Books of an Author and Adding a New Book56
Fetching all Books of an Author and Deleting a Book57
Item 4: How to Effectively Shape the @ManyToMany Association58
Choose the Owner of the Relationship59
Always Use Set not List59
Keep Both Sides of the Association in Sync59
Avoid CascadeType.ALL and CascadeType.REMOVE59
Setting Up the Join Table60
Using Lazy Fetching on Both Sides of the Association60
Override equals() and hashCode()60
Pay Attention to How toString() Is Overridden60
Author and Book Samples60
Item 5: Why Set Is Better than List in @ManyToMany64
Using List64
Using Set66
Preserving the Order of the Result Set67
Using @OrderBy68
Item 6: Why and When to Avoid Removing Child Entities with CascadeType.Remove and orphanRemoval=true69
Deleting Authors that Are Already Loaded in the Persistence Context73
One Author Has Already Been Loaded in the Persistence Context73
More Authors Have Been Loaded in the Persistence Context74
One Author and His Associated Books Have Been Loaded in the Persistence Context76
Deleting When the Author and Books that Should Be Deleted Are Not Loaded in the Persistence Context78
Item 7: How to Fetch Associations via JPA Entity Graphs80
Defining an Entity Graph via @NamedEntityGraph81
Overriding a Query Method82
Using the Query Builder Mechanism83
Using Specification84
Using @Query and JPQL85
Ad Hoc Entity Graphs87
Defining an Entity Graph via EntityManager89
Item 8: How to Fetch Associations via Entity Sub-Graphs90
Using @NamedEntityGraph and @NamedSubgraph92
Using the Dot Notation (.) in Ad Hoc Entity Graphs95
Defining an Entity Sub-Graph via EntityManager98
Item 9: How to Handle Entity Graphs and Basic Attributes98
Item 10: How to Filter Associations via a Hibernate-Specific @Where Annotation103
Item 11: How to Optimize Unidirectional/Bidirectional @OneToOne via @MapsId107
Regular Unidirectional @OneToOne107
Regular Bidirectional @OneToOne110
@MapsId to the Rescue of @OneToOne112
Item 12: How to Validate that Only One Association Is Non-Null115
Testing Time117