انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهMID-021-L01

خطط الجلب حسب حالة الاستخدام

  • الدرس 1 من 6
  • Mid-level
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

load exactly the data each use case needs.

الموضوعات المخطط لها

  • Associations should be LAZY by default; decide the fetch per use case, not on the mapping.
  • JOIN FETCH or 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 (@BatchSize or default_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.
تفاصيل المخطط المبدئي

عرض عملي

java
@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.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.