2.5.2. Field and Property Metadata
The persistence implementation must be able to retrieve and set the persistent state of your entities, mapped superclasses, and embeddable types. JPA offers two modes of persistent state access: field access, and property access. The access type of a persistent attribute can be either set explicitly on a class or attribute level, inherited, or determined by the provider.
Under field access, the implementation injects state directly into your persistent fields, and retrieves changed state from your fields as well.
To declare field access on an entire entity with XML metadata, set the access attribute of your entity XML element to FIELD.
To use field access for an entire entity using annotation metadata, simply place your metadata and mapping annotations on your field declarations:
@ManyToOne
private Company publisher;
Property access, on the other hand, retrieves and loads state through JavaBean "getter" and "setter" methods.
For a property p of type T, you must define the following getter method:
T getP();
For boolean properties, this is also acceptable:
boolean isP();
You must also define the following setter method:
void setP(T value);
To implicitly use property access for an entire class by default, set your entity element’s access attribute to PROPERTY, or place your metadata and mapping annotations on the getter method:
@ManyToOne
private Company getPublisher() { ... }
private void setPublisher(Company publisher) { ... }