انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-032-L04

الترقيم مع المجموعات (Collections)

  • الدرس 4 من 7
  • Junior
في هذا الدرس 4 موضوعات

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

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

في هذا الدرس

avoid fetch-joining a collection with paging.

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

  • A join fetch on a collection multiplies parent rows (one row per child).
  • Hibernate cannot page that in SQL, so it loads everything and pages in memory (warning HHH000104: verify wording for your version).
  • That can exhaust memory on big tables.
  • Safe approach: page the parent ids first, then load children for those ids with a second query.
  • Alternative: use @BatchSize or a projection.
تفاصيل المخطط المبدئي

عرض عملي

java
Page<Long> ids = orderRepository.findIds(pageable);                 // page the parents only
List<Order> orders = orderRepository.findWithLinesByIdIn(ids.getContent()); // fetch join

اختبر فهمك

Why is join fetch on a collection plus paging dangerous?

أظهر الإجابة

Paging happens in memory after loading all rows.

التطبيق

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

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

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

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