Spring Boot, Java, Data Migration, Programming, Technology.
userRepository.findById(userId).orElseThrow(RuntimeException::new); Hibernate.initialize(user.getOrders()); // Explicitly initializing orders when needed return user; } } In the UserService, the getUserWithOrders method fetches a User and initializes the orders only when needed. This approach