الترقيم مع المجموعات (Collections)
في هذا الدرس 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
@BatchSizeor a projection.
تفاصيل المخطط المبدئي
عرض عملي
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.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.