background image

Persistent Fields and Properties

<< Introduction to the Java Persistence API | Persistent Properties >>
<< Introduction to the Java Persistence API | Persistent Properties >>

Persistent Fields and Properties

Entities may extend both entity and non-entity classes, and non-entity classes may extend
entity classes.
Persistent instance variables must be declared private, protected, or package-private, and
can only be accessed directly by the entity class's methods. Clients must access the entity's
state through accessor or business methods.
Persistent Fields and Properties in Entity Classes
The persistent state of an entity can be accessed either through the entity's instance variables or
through JavaBeans-style properties. The fields or properties must be of the following Java
language types:
Java primitive types
java.lang.String
Other serializable types including:
Wrappers of Java primitive types
java.math.BigInteger
java.math.BigDecimal
java.util.Date
java.util.Calendar
java.sql.Date
java.sql.Time
java.sql.TimeStamp
User-defined serializable types
byte[]
Byte[]
char[]
Character[]
Enumerated types
Other entities and/or collections of entities
Embeddable classes
Entities may either use persistent fields or persistent properties. If the mapping annotations are
applied to the entity's instance variables, the entity uses persistent fields. If the mapping
annotations are applied to the entity's getter methods for JavaBeans-style properties, the entity
uses persistent properties. You cannot apply mapping annotations to both fields and properties
in a single entity.
Entities
The Java EE 5 Tutorial · September 2007
686