1.必须有一个无参数的构造函数
2.不能定义成final类,实体中的方法也不能是final
3.必须定义身份字段,或者主键
4.版本字段,JPA用它来检测对同一条记录的并发操作
5.继承,支持持久化类继承非持久化类,持久化类继承其它持久化类,非持久化类继承持久化类.但需要主要几点:不能继承系统类,如java.net.Socket
and java.lang.Thread
,如果继承非持久化类 ,则非持久化的字段不能被持久。继承树上所有的类都必须使用同一身份类型
6.持久化字段。不支持final和静态字段,持久化的字段类型包含3种:immutable 类型, mutable 类型, relations 类型。
immutable类型,一旦创建,就不能改变。支持如下的immutable类型:
-
All primitives (
int, float, byte
, etc) -
All primitive wrappers (
java.lang.Integer, java.lang.Float, java.lang.Byte
, etc) -
java.lang.String
-
java.math.BigInteger
-
java.math.BigDecimal
byte[]
,Byte[]
,char[]
, andCharacter[]
支持的mutable类型:
-
java.util.Date
-
java.util.Calendar
-
java.sql.Date
-
java.sql.Timestamp
-
java.sql.Time
-
Enums
-
Entity types (relations between entities)
-
Embeddable types
-
java.util.Collection
s of entities -
java.util.Set
s of entities -
java.util.List
s of entities -
java.util.Map
s in which each entry maps the value of one of a related entity's fields to that entity.