Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop Data access resources > Develop data access applications > Develop data access applications > Benefits of resource references
Requirements for setting data access isolation levels
This article discusses the criteria and effects of setting isolation levels for data access components that comprise EJB 2.x and later modules.
In an EJB 1.1 module, you can set the isolation level at the method level or bean level. This capability also applies to container-managed persistence (CMP) 1.1 beans that you assemble into EJB 2.x modules. WAS permits the deployment descriptor of a CMP bean to declare the version level of 1.1, regardless of the overall module version.
However, the ability to set isolation level at the method or bean level does not apply to other enterprise beans within an EJB 2.x module, including CMP 2.x beans. WAS v5.0 removed this capability from EJB 2.0 modules to deliver an architecture that ultimately provides more efficient connection use.
Consequently, later versions of the product enforce the following restrictions on declaring isolation level for CMP 2.x beans—as well as session beans, message-driven beans, and bean managed persistence (BMP) beans that you assemble into EJB 2.x modules:
- We cannot specify isolation level on the EJB method level or bean level.
- If you configure a JDBC application, a bean-managed persistence (BMP) bean, or a servlet to participate in global transactions, any connection shared cannot accept a user-specified isolation level. WAS can only set a user-specified isolation level on a connection that is not shared within a global transaction. Generally, you want to refrain from specifying isolation levels on shareable connections.
The configuration for the isolation level is determined by the type of bean used by the component:
Isolation level on connections used by 2.x CMP beans
In a EJB 2.x module, when a CMP 2.x 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 assigned to the bean or the calling method. Other non-CMP connection users can access this same data source and also use the access intent and application profile support to manage their concurrency control.
Connections used by other 2.x enterprise beans and other non-CMP components
For all other JDBC connection instances (connections other than those used by CMP beans), you can specify an isolation level on the data source resource reference. For shareable connections that run in global transactions, this method 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 your assembly tool.
Each resource reference associates with one isolation level. When the 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. Consider the following scenario:
- 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 the 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.
If you do not specify the isolation level:
The product does not require you to set the isolation level on a data source resource reference for a non-CMP application module. If you do not specify isolation level on the resource reference, or if you specify TRANSACTION_NONE, the WAS run time uses a default isolation level for the data source. Application Server uses a default setting based on the JDBC driver.
For most drivers, WAS uses an isolation level default of TRANSACTION_REPEATABLE_READ. For Oracle drivers, however, Application Server uses an isolation level of TRANSACTION_READ_COMMITTED. Use the following table for quick reference:
Database: Default isolation level: DB2 RR Oracle RC Sybase RR Informix RR Apache Derby RR SQL Server RR
- Note: These same default isolation levels are used in cases of direct JNDI lookups of a data source.
- RR = JDBC Repeatable read (TRANSACTION_REPEATABLE_READ)
- RC = JDBC Read committed (TRANSACTION_READ_COMMITTED)
To customize the default isolation level, you can use the webSphereDefaultIsolationLevel custom property for the data source. In most cases you should define the isolation level in the deployment descriptor when you package the EAR file, but in certain situations you might need to customize the default isolation level. This property will have no effect if any of the above options are used, and this custom property is provided for those situations in which there is no other means of setting the isolation level.
Use the following values for webSphereDefaultIsolationLevel custom property:
To define this custom property for a data source:
Possible values JDBC isolation level DB2 isolation level 8 TRANSACTION_SERIALIZABLE Repeatable Read (RR) 4 (default) TRANSACTION_REPEATABLE_READ Read Stability (RS) 2 TRANSACTION_READ_COMMITTED Cursor Stability (CS) 1 TRANSACTION_READ_UNCOMMITTED Uncommitted Read (UR)
- Click Resources > JDBC provider > JDBC_provider .
- Click Data sources in the Additional Properties section.
- Click the name of the data source.
- Click Custom properties.
- Create the webSphereDefaultIsolationLevel custom property.
- Click New.
- Enter webSphereDefaultIsolationLevel for the name field.
- Enter one of the possible values in the value field.
Application Server sets the isolation level by prioritizing the available settings. Application Server will set the isolation level based on the values for the following, in this order:
- Resource reference isolation level
- Isolation level specified by the access intent policy
- Custom property that configures an isolation level
- Application Server's default setting.
Related
Data source lookups for enterprise beans and web modules
Direct and indirect JNDI lookup methods for data sources
Access intent service
Data sources
Unshareable and shareable connections
Assembly tools
Create or changing a resource reference using the assembly tool
Access data from application clients
Configure data access for the Application Client
Assembling data access applications using the assembly tool
Access data using Java EE Connector Architecture connectors
Migrate applications to use data sources of the current Java EE Connector Architecture (JCA)
Configure a JDBC provider and data source