Application performance and entity bean behavior
WebSphere Application Server allows us to override two behaviors required by the EJB specification, because the application might benefit from handling these aspects of bean data management in a slightly different manner.
Application-managed persistent store synchronization for findBy methods
Sections 10.5.3 and 12.1.4.2 of the EJB 2.0 and 2.1 specifications require that prior to running a query as part of any findBy method (except for findByPrimaryKey), the EJB container writes out to persistent storage the state of any entity beans of the type that are enlisted in the current transaction. Stated another way, the container performs the following actions:
If the state of an EJB instance is not altered in the current transaction, the store operation is skipped for that instance. This practice ensures that the query is performed on the most current state of all the persistent data, reducing the chance of data integrity issues.
- Creates a list of beans that are both enlisted in the current transaction and are of the same type that the findby method is returning
- Stores the state of these enterprise beans to persistent storage before running the query
However, there are scenarios where it is inefficient and wasteful for the EJB container to automatically perform this action on every findBy method. Examples of this would be where the application itself ensures that the most current data is used on findBy queries, or where the application can tolerate some non-current data as part of the query results.
WebSphere Application Server allows us to initiate the synchronization process under application control, and to disable the container-managed synchronization for specific EJB types within the application. Careful use of these functions can improve the performance of the application without sacrificing data integrity. Refer to the topic Manipulating the synchronization of entity beans and datastores.
Avoiding ejbStore invocations on non-modified entity bean instances
The EJB specification requires that the EJB container invoke the user-provided ejbStore method on all entity beans within a transaction when that transaction is committed. For container-managed persistence (CMP) beans (as opposed to bean-managed persistence beans) this operation is usually unnecessary, because this method on CMP beans is often empty. Even in cases where the method is not empty, the application might only require the method to be called if the bean's persistent state is modified during the current transaction.
WebSphere Application Server provides a mechanism for you to indicate if we want this behavior for specific EJB types within the application. See the topic Avoiding ejbStore invocations on non-modified EntityBean instances.
Related tasks
Manipulating synchronization of entity beans and datastores Avoiding ejbStore invocations on non-modified EntityBean instances