عرض عملي: اصطياد N+1 باختبار يعدّ الاستعلامات
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
write a test that fails when queries multiply; prepares JNR-032-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Seed 100 orders with lines in a test.
- Add a query counter (Hibernate statistics or a datasource-proxy library; verify your choice).
- Call the order-history endpoint and print the count: 101.
- Write the assertion
queryCount <= 2; the test fails. - Planned mistake: add
fetch = EAGERand show the count is still high; revert it. - Add the
join fetchor entity graph; the test passes.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.