Read-ahead 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 that are most likely to be needed next by an application. A read-ahead hint is a representation of the related beans that are to be read. It 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. You do not have to provide the string; the wizard generates it for you based on CMRs defined for the bean. The following example is provided as 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 that is 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 their 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), a bean's data columns appear only once, at the position it first appears in the hint.

The tokens shown in the notation (RelB and so on) 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 a relationship employees with the Employee bean and also has a relationship manager 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.

 

Some things to consider

When developing your read-ahead

hints, you should keep the following in mind:

  • Read ahead on long or complex paths can result in a query that is too complex to be useful. Read ahead on root or leaf inheritance mappings need particular care. You should add up the number of tables that are involved in the preload and then consider whether a join that complex is really a reasonable query on your target database.

  • Read ahead does NOT work in the following cases:

    • preload paths across M:N relationships

    • preload paths across recursive enterprise bean relationships or recursive fk relationships

    • where multiple instances of the same table occur on the same path (whether through a recursive relationship or not).

    • when readAhead contains a table join. Different access intents can result in requiring a select for update statement. Check the matrix on the JDBC driver and select for update support to see if readAhead is enabled.


 

See Also


Access intent policies
Concurrency control

 

Related Tasks


Using access intent policies

 



 

 

Rational is a trademark of the IBM Corporation in the United States, other countries, or both.