N + 1 problem and solution
* The N + 1 select problem is a performance issue in Hibernate. In this problem, a Java application makes N + 1 database calls (N = number of child objects fetched). For example, if N = 2, the application makes 3 (N + 1 = 3) database calls. package com.example.cascade_types_and_n_plus_one_problem.entity ; import jakarta.persistence.* ; import lombok.* ; import org.hibernate.Hibernate ; import java.util.ArrayList ; import java.util.List ; import java.util.Objects ; @Getter @Setter @ToString @RequiredArgsConstructor @Entity public class Department { @Id @GeneratedValue (strategy = GenerationType. IDENTITY ) private Long id ; private String name ; @OneToMany (mappedBy = "department" , cascade = CascadeType. ALL , fetch = FetchType. EAGER ) private List<Employee> employees = new ArrayList<>() ; @Override public boolean equals (Object o) { if ( this == o) return true; if (o == null || Hibernate. getClass ( this ) != Hiber...