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

Fetch joins وEntity graphs

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

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

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

في هذا الدرس

load related data in one query.

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

  • join fetch in JPQL loads the relation together with the parent.
  • @EntityGraph(attributePaths = "lines") on a repository method does the same without writing JPQL.
  • A projection that selects only needed columns can avoid loading entities at all.
  • Fetch what the use case needs, not everything.
  • Verify with the log or the query counter.
تفاصيل المخطط المبدئي

عرض عملي

java
@Query("select distinct o from Order o join fetch o.lines where o.customer.id = :cid")
List<Order> findWithLines(@Param("cid") Long cid);

@EntityGraph(attributePaths = {"lines", "customer"})
List<Order> findByStatus(OrderStatus status);

اختبر فهمك

Name two ways to fix N+1 besides projections.

أظهر الإجابة

Fetch join and entity graph.

التطبيق

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

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

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

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