Giriş
Şu satırı dahil
ederiz.
import javax.persistence.Entity;
Bir sınıfın JPA ile kullanılabilmesi için @Entity ile işaretlenmesi
gerekir.
@Entity
public class MyEntity {
...
}
Hibernate İle Kullanımı
Bir çok JPA sağlayıcısı, JPA ile gelmeyen diğer özellilkler de sunar. Bu özellikler kullanılabilir.
@Entity
@org.hibernate.annotations.Entity(optimisticLock=OptimisticLockType.ALL)
public class MyEntity implements Serializable {
...
}
Entity Sınıfı No-Arg Constructor
Entity sınıfı public veya protected bir no-arfg constructor'a sahip
olmalıdır.
- The entity class must have a no-arg constructor. It may have other constructors as well. The no-arg constructor must be public or protected.
- The entity class must a be top-level class. An enum or interface must not not be designated as an entity.
- The entity class must not be final. No methods or persistent instance variables of the entity class may be final.
- If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.
- Both abstract and concrete classes can be entities. Entities may extend non-entity classes as well as entity classes, and non-entity classes may extend entity classes.
Entity Sınıfı final olmamalıdır.
Bu örnek
yanlıştır.
@Entity
public final class MyEntity {
...
}