Configuring WSJPA ObjectCache to improve performance
The WebSphere® Java™ Persistence API (WSJPA) extension to OpenJPA provides a read-only object cache that can improve performance in certain use cases. This configuration is only supported when you use WSJPA at the JPA 2.0 specification level.
About this task
Implementing a WSJPA ObjectCache object can improve the performance of an application that has a set of data that is used in a static, read-only method, like accessing basic persistent fields and persisting unidirectional relationships to a read-only type. WSJPA ObjectCache is a non-distributed cache of read-only entities that operates at the EntityManagerFactory object level. These cached instances are shared by all EntityManager objects in the Java virtual machine (JVM), but the instances are not managed by any. When the feature is enabled, the ObjectCache object is examined before the application accesses the OpenJPA DataCache object and database, and persistent objects are loaded from the database and stored in the OpenJPA object cache. In addition, the ObjectCache implementation can be used with OpenJPA DataCache and QueryCache features for even greater performance.
- Include types that are strictly read-only from the application
point-of-view
- Passing a read-only type into the following operations results
in an UnsupportedOperationException error message:
- Passing a read-only entity into EntityManager.merge(…).
- Passing a read-only entity into EntityManager.persist(…).
- Passing a read-only entity into EntityManager.remove(…).
- Calling a setter method on a read-only type that was returned by the WebSphere JPA runtime results in an UnsupportedOperationException error message.
- Passing a read-only type into the following operations results
in an UnsupportedOperationException error message:
- Types that are included in the ObjectCache must not be eligible to be cached in the OpenJPA DataCache. Do not intersect types that are cacheable by the OpenJPA L2 cache (openjpa.DataCache); the ObjectCache should not be confused with the second-level cache that is defined by the JPA 2.0 specification. If types are intersected, an exception will occur when the EntityManager object is created.
- Include only basic fields, or an exception can occur when the EntityManager object is created.
- Passing a read-only entity into EntityManager.contains(…) always returns false, even if it was just returned from a find/query operation.
