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

Embeddables وكائنات القيمة (Value objects)

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

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

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

في هذا الدرس

store a value object in the owner's table.

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

  • A value object has no identity of its own; Money is just amount plus currency.
  • @Embeddable marks the class; @Embedded uses it in an entity.
  • Its fields become columns of the owner's table (granularity solved).
  • Rename columns with @AttributeOverride if the same embeddable appears twice.
  • Make value objects immutable.
تفاصيل المخطط المبدئي

عرض عملي

java
@Embeddable
public record Money(
    @Column(name = "price_amount") BigDecimal amount,
    @Column(name = "price_currency", length = 3) String currency) {}

// in Product:
@Embedded private Money price;

اختبر فهمك

Does an embeddable get its own table?

أظهر الإجابة

No; its columns live in the owner's table.

التطبيق

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

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

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

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