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.

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.

Be aware of the following conditions and limitations:
  • 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.
  • 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.
You can enable the object cache for a single JVM environment, specify the types that are included in this cache, set its maximum element size, and specify timeout values.
Supported configurations Supported configurations: The preferred property name is wsjpa.ObjectCache, but openjpa.ObjectCache is also a valid configuration.sptcfg

Procedure

What to do next

To enable automatic loading of the entire ObjectCache when the first EntityManager object is created, follow the steps in the Pre-loading the WSJPA ObjectCache automatically topic. In addition, you can read more about caching in the OpenJPA User Guide for information about all caching extensions.
Task topic    

Terms and conditions for information centers | Feedback

Last updated: April 17, 2014 10:32 PM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-express-iseries&topic=tejb_jpaobjectcache
File name: tejb_jpaobjectcache.html