Isolation level and resource reference


You cannot specify isolation level on the EJB method level or bean level. Also, if a JDBC application, a bean-managed persistence bean, or a servlet runs in a global transaction, and you are using shareable connections, you cannot set the isolation level on a connection.

When a container-managed persistence bean uses a new data source to access a backend database, the isolation level is determined by the WAS run time based on the type of access intent that this method or the bean has chosen. All other connection users can also use the access intent and application profile support to manage their concurrency control.

For all JDBC connections (excluding those used by CMP beans), you can specify an isolation level default on the resource reference. For shareable connections that run in global transactions, this default is the only way to set the isolationLevel for connections. Trying to directly set the isolation level through the setTransactionIsolation() method on a shareable connection that runs in a global transaction is not allowed. To use a different isolation level on connections, provide a different resource reference. Set these defaults through the Assembly Toolkit (ATK).

Each resource reference associates with one isolation level. When your application uses this resource reference JNDI name to look up a data source, every connection returned from this data source using this resource reference has the same isolation level.

Components needing to use shareable connections with multiple isolation levels can create multiple resource references, giving them different JNDI names, and have their code look up the appropriate data source for the isolation level they need. In this way, you use separate connections with the different isolation levels enabled on them.

It is possible to map these multiple resource references to the same configured data source. The connections still come from the same underlying pool, however, the connection manager does not allow sharing of connections requested by resource references with different isolation levels.

For example, a data source is bound to two resource references: jdbc/RRResRef and jdbc/RCResRef. RRResRef has the RepeatableRead isolation level defined. RCResRef has the ReadCommitted isolation level defined. If your application wants to update the tables or a BMP bean updates some attributes, it can use the jdbc/RRResRef JNDI name to look up the data source instance. All connections returned from the data source instance have a RepeatableRead isolation level. If the application wants to perform a query for read only, then it is better to use the jdbc/RCResRef JNDI name to look up the data source.