خطط الجلب حسب حالة الاستخدام
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
load exactly the data each use case needs.
الموضوعات المخطط لها
- Associations should be
LAZYby default; decide the fetch per use case, not on the mapping. JOIN FETCHor an entity graph loads an association in one query; avoids N+1.- Fetching two collections at once creates a cartesian product; fetch one collection and batch the others (
@BatchSizeordefault_batch_fetch_size). - For read-only screens, a DTO projection selects only needed columns and skips the persistence context.
- Pagination with a fetched collection is done in memory by Hibernate (warning
HHH000104); paginate ids first.
تفاصيل المخطط المبدئي
عرض عملي
@EntityGraph(attributePaths = "items")
Optional<Order> findWithItemsById(Long id);
@Query("select new com.shop.OrderSummary(o.id, o.total, c.name) from Order o join o.customer c")
List<OrderSummary> summaries();اختبر فهمك
Why a DTO projection for a list screen?
أظهر الإجابة
It loads only the needed columns and creates no managed entities.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.