Embeddables وكائنات القيمة (Value objects)
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
store a value object in the owner's table.
الموضوعات المخطط لها
- A value object has no identity of its own;
Moneyis just amount plus currency. @Embeddablemarks the class;@Embeddeduses it in an entity.- Its fields become columns of the owner's table (granularity solved).
- Rename columns with
@AttributeOverrideif the same embeddable appears twice. - Make value objects immutable.
تفاصيل المخطط المبدئي
عرض عملي
@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.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.