ربط كيان بجدول (Mapping an entity)
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
turn a class into a table mapping.
الموضوعات المخطط لها
@Entitymarks a class as persistent;@Idmarks its primary key.- JPA needs a no-argument constructor (protected is fine); entities are normal classes, not records.
@Tableand@Columnset names, length, and nullability; they should match the real schema.- Store enums with
@Enumerated(EnumType.STRING), never the default ordinal (numbers break when you reorder). - Entities model the database, not the API: do not return them from controllers.
تفاصيل المخطط المبدئي
عرض عملي
@Entity
@Table(name = "product")
public class Product {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 120)
private String name;
@Enumerated(EnumType.STRING)
private ProductStatus status;
protected Product() {}
}اختبر فهمك
Which enum mapping is safe?
أظهر الإجابة
EnumType.STRING.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.