انتقل إلى المحتوى
أمين أبوزيد
JNR-027

أساسيات ORM

  • 4 درس
  • 1 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

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

نظرة عامة

الموضوعات

  • عدم التطابق بين الكائنات والجداول (Object-relational impedance mismatch)
  • سياق الاستمرارية (Persistence context)

تعلّم أولًا

1 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Explain the object-relational impedance mismatch (identity, inheritance, associations, granularity).
  2. Describe what an ORM automates and what it costs.
  3. Explain the persistence context as an identity map and unit of work.

الدروس

  1. 01الكائنات مقابل الجداول
  2. 02ماذا يفعل ORM
  3. 03سياق الاستمرارية (Persistence context)
  4. 04عرض عملي: مراقبة سياق الاستمرارية عبر تسجيل SQL

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

Lab

JNR-027-LAB1 · Mismatch exercise

Outcomes: 1–3 · Time: ~1 h

  1. Open the Spring JDBC ProductRepository from JNR-026.
  2. List every piece of mapping code: SQL strings, row mappers, key handling, null handling, type conversions, joins assembled by hand.
  3. For each item, predict whether an ORM would remove it, change it, or leave it.
  4. For each, name one risk the ORM would add (hidden query, lazy loading, dirty checking surprise).
  5. Tag each item with the mismatch it belongs to (identity, inheritance, associations, granularity).

Acceptance: a reasoned list with a prediction and a risk for every mapping item.

Exercises (assessment: quiz)

IDOutcomeTask
JNR-027-EX011Name the four mismatches and give a one-line Shop example of each.
JNR-027-EX021Explain why Order with List<OrderLine> has no direct table equivalent.
JNR-027-EX032List three things an ORM automates and three costs it introduces.
JNR-027-EX042Explain why "we use an ORM so we do not need SQL" is wrong.
JNR-027-EX053Predict the number of selects for: find(1), find(1), find(2) in one transaction.
JNR-027-EX063Explain why changing a loaded entity without calling save can still update the row.
أظهر الحلول
  • EX01 Identity: two Product objects with the same id; inheritance: DigitalProduct extends Product; associations: Order-OrderLine; granularity: Money as amount and currency columns.
  • EX02 A list lives inside the object; in the database each line is a row in another table pointing back with a foreign key.
  • EX03 Automates: generated SQL, row mapping, change tracking. Costs: hidden queries, N+1 risk, learning curve and debugging effort.
  • EX04 You must design the schema, read generated SQL, write queries for reports, and diagnose slow statements.
  • EX05 Two selects; the second find(1) comes from the identity map.
  • EX06 The persistence context tracks managed entities and writes changes at flush (dirty checking: unit of work).
  • Outcome coverage: the quiz also tests all three outcomes.

الاختبار

Outcomes: O1 impedance mismatch · O2 what an ORM does and costs · O3 persistence context.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1The object-relational impedance mismatch is:O1
  2. 2Which is NOT one of the classic mismatches?O1
  3. 3A Money value object stored as two columns shows a mismatch of:O1
  4. 4An ORM automates:O2
  5. 5A real cost of an ORM is:O2
  6. 6JPA is:O2
  7. 7With an ORM you still need SQL knowledge to:O2
  8. 8The persistence context works as:O3
  9. 9find(1) twice in one transaction issues:O3
  10. 10Flush means:O3

الجزء العملي

Six exercises JNR-027-EX01 to EX06 plus the lab; the assessment is this quiz. Pass: at least 8 of 10 quiz questions and a reasoned lab list.

أخطاء شائعة

Believing an ORM removes the need to know SQL.

التقييم

Quiz.

الصلة بالمسار الوظيفي

Basis for diagnosing ORM issues (JNR-032, MID-021).

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