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

ربط كيان بجدول (Mapping an entity)

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

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

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

في هذا الدرس

turn a class into a table mapping.

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

  • @Entity marks a class as persistent; @Id marks its primary key.
  • JPA needs a no-argument constructor (protected is fine); entities are normal classes, not records.
  • @Table and @Column set 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.
تفاصيل المخطط المبدئي

عرض عملي

java
@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.

التطبيق

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

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

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

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