Manipulating synchronization of entity beans and datastores
We can indicate that a particular EJB type should not synchronize its state to persistent storage prior to each findBy invocation by using environment variables or a marker interface.
There are two options available for indicating that a particular EJB type should not synchronize its state to persistent storage prior to each findBy invocation:
- Set an EJB environment variable within the bean's deployment descriptor
- Have the bean implementation class implement a marker interface. This second technique is especially useful if we have a number of bean implementations that all extend a single root class; in this case we can have the root class implement the marker interface, causing all beans that extend this class to inherit the behavior as well.
- To use the EJB environment variable technique, edit the EJB deployment descriptor using any standard Java EE development tool. For information on the tool options, see the topic, Assembly tools.
- Start the tool.
- Select the EJB deployment descriptor of the bean with which to work.
- Create an EJB environment variable with the name com/ibm/websphere/ejbcontainer/disableFlushBeforeFind.
- Set the type of this variable to java.lang.Boolean.
- Set the value to True to prevent the pre-find synchronization, or False to enable the default behavior.
- Save the changes.
- To use a marker interface, code the bean implementation class to implement the com.ibm.websphere.ejbcontainer.disableFlushBeforeFind interface. The bean implementation class need not directly implement the interface; any parent class can implement the interface. See the com.ibm.websphere.ejbcontainer package in the Reference > Developer > API documentation section of the information center.
Ensuring data integrity for queries performed during a transaction
If we choose to disable the automatic pre-find synchronization for certain bean types, it is very important that the application use other means to ensure that queries performed during the transaction are not performed on data that might no longer be valid. We can use the flushCache method on the com.ibm.websphere.ejbcontainer.EJBContextExtension class (an extension of javax.ejb.EJBContext) to perform a manual synchronization to persistent storage at times defined by the application. For more information on EJBContextExtension and its related classes SessionContextExtension, EntityContextExtension and MessageDrivenContextExtension, see the com.ibm.websphere.ejbcontainer package in the Reference > Developer > API documentation section of the information center.
Related concepts
Development and assembly tools
Related information: