انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهMID-016-L01

القفل المتفائل

  • الدرس 1 من 7
  • Mid-level
في هذا الدرس 4 موضوعات

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

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

في هذا الدرس

detect concurrent edits with a version column.

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

  • Add @Version long version to the entity; Hibernate adds WHERE id = ? AND version = ? to every update and increments the version.
  • If zero rows are updated, it throws OptimisticLockException (Spring: ObjectOptimisticLockingFailureException).
  • No database lock is held while the user thinks; it suits low-conflict workloads.
  • Expose the version to clients (ETag or a field) so edits across requests are protected too.
  • Map the exception to HTTP 409 with the current state.
تفاصيل المخطط المبدئي

عرض عملي

java
@Entity class Product {
  @Id Long id;
  @Version long version;
  String name;
}

اختبر فهمك

What does Hibernate add to the update statement?

أظهر الإجابة

A check that the version is still the one that was read.

التطبيق

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

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

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

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