The Java Persistence API (JPA) is a very flexible specification that provides guidelines on how implementors are to translate relational data to Java object form. Due to the flexible nature of this API, a large amount of work is completed at runtime by the API provider to determine how to correctly load relational data into object form. This flexibility results in a runtime that, under certain circumstances, has to continually run redundant code to ensure that data is loaded properly. By giving up some of this flexibility, the WSJPA FastPath optimization attempts to skip much of this redundant code and generates highly optimized code that interacts directly with the JDBC layer.
Optimizing these code paths is a very complex process, and as such, not all domain models satisfy the requirements for WSJPA FastPath optimizations.
The Fastpath feature can improve the performance of some applications which have their data modeled in an acceptable format and are not using extended JPA features.
public Customer findCustomer(int id) {
return em.find(Customer.class, id);
}
This example is a simple helper method that finds a customer entity. Every time the findCustomer method is invoked, the JPA runtime executes large amounts of code to analyze the request, to access the database, and to load the Customer Entity. Without the use of the FastPath optimization, most of the logic is identical for the second and subsequent executions of the findCustomer method. Very few of the runtime decisions from the first execution are retained for future invocations of the findCustomer method. This redundant code processing can cause performance issues for some scenarios.
10855 fp_pu INFO [main] FP - Successfully generated FastPath com.ibm.ws.persistence.fastpath.entities.Customer$Find$FastPath@1f6b69d7".
When this message is logged, all future executions of finding a Customer use this new generated path.
The previous example outlined how a finder path might be executed. FastPath also attempts to optimize lazy loading of fields (relationship and non-relationship) and executing NamedQueries.
Configuring FastPath:
When persistence unit property wsjpa.FastPath=true is set, the JPA runtime attempts to determine which operations can be safely handled. The Include and Exclude properties can be used to explicitly configure which operations are executed using FastPath.
<property name=”openjpa.MetaDataRepository” value=”Preload=true”/>
<property name=”wsjpa.FastPath”
value=”true(Include=’<path>;,<path>;...’;Exclude=’<path>,<path>...’)”>
<property name="wsjpa.FastPath" value="false"/>
In
this example, false is the default value; this optimization
is not turned on by default.<property name="wsjpa.FastPath" value="true"/>
The
runtime processes all entities and attempts to determine which finders,
lazy load operations, and named queries can be optimized.<property name="wsjpa.FastPath" value="true(Exclude=com.ibm.ws.jpa.entities.Customer.address,customer.findById"/>
Same
as in example #2, except lazy loading the Customer.address field and
the named query customer.findById are excluded from FastPath processing.<property name="wsjpa.FastPath" value="true(Include=com.ibm.ws.jpa.entities.Customer, customer.findById"/>
The only operations that are processed are finding a Customer
and executing the NamedQuery ‘customer.findById’. All other operations
are executed using the normal JPA runtime.Limitations:
@org.apache.openjpa.persistence.Factory, @javax.persistence.SecondaryTable,
@org.apache.openjpa.persistence.Externalizer,
@org.apache.openjpa.persistence.ExternalValues,
@org.apache.openjpa.persistence.LRS, @java.sql.Lob, @java.sql.Clob, @java.sql.Blo