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

سياق الاستمرارية (Persistence context)

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

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

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

في هذا الدرس

explain the persistence context as an identity map and a unit of work.

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

  • The persistence context is a per-transaction workspace holding the entities you loaded.
  • Identity map: asking for the same id twice returns the same Java object, with no second query.
  • Unit of work: it remembers the original state; at flush time it compares and writes only what changed.
  • Flush means "send pending SQL now"; commit makes it permanent.
  • Entities outside the workspace are detached: changes to them are not saved.
تفاصيل المخطط المبدئي

عرض عملي

java
Product a = em.find(Product.class, 1L); // SQL select
Product b = em.find(Product.class, 1L); // no SQL, from the identity map
System.out.println(a == b);             // true
a.setName("New");                       // tracked; update at flush

اختبر فهمك

Why does the second find issue no SQL?

أظهر الإجابة

The entity is already in the persistence context.

التطبيق

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

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

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

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