Read ahead scheme hints
read ahead schemes enable applications to minimize the number of database round trips by retrieving a working set of container-managed persistence (CMP) beans for the transaction within one query. read ahead involves activating the requested CMP beans and caching the data for their related beans, which ensures that data is present for the beans an application most likely needs next. A read ahead hint is a representation of the related beans to read. The hint is associated with the findByPrimaryKey method for the requested bean type, which must be an EJB 2.x-compliant CMP entity bean.
A read ahead hint takes the form of a character string. We do not have to provide the string; the wizard generates it based on the container-managed relationships (CMRs) defined for the bean. The example provided in this section is for supplemental information only. Suppose a CMP bean type A has a finder method that returns instances of bean A. A read ahead hint for this method is specified using the following notation: RelB.RelC; RelD
Interpret the preceding notation as follows:
- Bean type A has a CMR with bean types B and D.
- Bean type B has a CMR with bean type C.
For each bean of type A retrieved from the database, its directly-related B and D beans and its indirectly-related C beans are also retrieved. The order of the retrieved bean data columns in each row of the result set is the same as the order in the read ahead hint: an A bean, a B bean (or null), a C bean (or null), a D bean (or null). For hints in which the same relationship is mentioned more than once, for example, RelB.RelC;RelB.RelE, the data columns for a bean occur only once in the result set, at the position the bean first occupies in the hint.
The tokens shown in the notation, like RelB, must be CMR field names for the relationships, as defined in the deployment descriptor for the bean. In indirect relationships such as RelB.RelC, RelC is a CMR field name defined in the deployment descriptor for bean type B.
A single read ahead hint cannot refer to the same bean type in more than one relationship. For example, if a Department bean has an employees relationship with the Employee bean and also has a manager relationship with the Employee bean, the read ahead hint cannot specify both employees and manager.
For more information about how to set read ahead hints, see the documentation for the Rational Application Developer product.
Run-time behaviors of read ahead hints
When developing your read ahead hints, consider the following tips and limitations:
- read ahead hints on long or complex paths can result in a query that is too complex to be useful. read ahead hints on root or leaf inheritance mappings need particular care. Add up the number of tables that potentially comprise a read ahead preload to gauge the complexity of the join operations required. Consider if the resulting statement constitutes a reasonable query on the target database.
- read ahead hints do not work in the following cases:
- Preload paths across M:N relationships
- Preload paths across recursive enterprise bean relationships or recursive fk relationships
- When a read-head hint applies to a SELECT FOR UPDATE statement that requires a table join in a database that does not support the combination of those two operations.
Generally, the persistence manager issues a SELECT FOR UPDATE statement for a bean only if the bean has an access intent that enforces strict locking policies. Strict locking policies require SELECT FOR UPDATE statements for database select queries. If the database table design requires a join operation to fulfill the statement, many databases issue exceptions because these databases do not support table joins with SELECT FOR UPDATE statements. In those cases, WebSphere Application Server does not implement a read ahead hint. If the database does provide that support, Application Server implements the read ahead hints that we configure.
DB2 Universal Databaseā¢ V8.2 supports SELECT FOR UPDATE statements with table joins.
Related:
Access intent policies for EJB 2.x entity beans Concurrency control Use access intent policies for EJB 2.x entity beans