Chapter 21.  Persistent Classes

Table of Contents

Persistent Class List
Enhancement
Enhancing at Build Time
Enhancing JPA Entities on Deployment
Enhancing at Runtime
Enhancing Dynamically at Runtime
Omitting the OpenJPA enhancer
Managed Interfaces
Object Identity
Datastore Identity
Entities as Identity Fields
Application Identity Tool
Autoassign / Identity Strategy Caveats
Managed Inverses
Persistent Fields
Restoring State
Typing and Ordering
Calendar Fields and TimeZones
Proxies
Externalization
Fetch Groups
Custom Fetch Groups
Custom Fetch Group Configuration
Per-field Fetch Configuration
Implementation Notes
Eager Fetching
Configuring Eager Fetching
Eager Fetching Considerations and Limitations

Persistent class basics are covered in Chapter 6, Entity of the JPA Overview. This chapter details the persistent class features OpenJPA offers beyond the core JPA specification.

Persistent Class List

Unlike many ORM products, OpenJPA does not need to know about all of your persistent classes at startup. OpenJPA discovers new persistent classes automatically as they are loaded into the JVM; in fact you can introduce new persistent classes into running applications under OpenJPA. However, there are certain situations in which providing OpenJPA with a persistent class list is helpful:

  • OpenJPA must be able to match entity names in JPQL queries to persistent classes. OpenJPA automatically knows the entity names of any persistent classes already loaded into the JVM. To match entity names to classes that have not been loaded, however, you must supply a persistent class list.

  • When OpenJPA manipulates classes in a persistent inheritance hierarchy, OpenJPA must be aware of all the classes in the hierarchy. If some of the classes have not been loaded into the JVM yet, OpenJPA may not know about them, and queries may return incorrect results.

  • If you configure OpenJPA to create the needed database schema on startup (see the section called “ Runtime Forward Mapping ”), OpenJPA must know all of your persistent classes up-front.

When any of these conditions are a factor in your JPA application, use the class, mapping-file, and jar-file elements of JPA's standard XML format to list your persistent classes. See the section called “ persistence.xml ” for details.

Alternately, you can tell OpenJPA to search through your classpath for persistent types. This is described in more detail in the section called “ Metadata Factory ”.

Note

Listing persistent classes (or their metadata or jar files) is an all-or-nothing endeavor. If your persistent class list is non-empty, OpenJPA will assume that any unlisted class is not persistent.