issue with setting transaction isolation level to read-committed

Has any had issues when setting the transaction isolation level for a connection pool?

My environment is:

SJSAS 8.2

jdk 1.5.0_08

MySQL Connector J 3.1.13

MySQL 5.0.22-standard

OS: Windows XP (application server) and Solaris 10 (MySQL database)

Here is my connection pool configuration:

General Settings

Name: MYSQL_EDGE

Datasource Classname: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource

Resource Type: javax.sql.ConnectionPoolDataSource

Description: DIY Edge Database

Pool Settings

Initial and Minimum Pool Size: 8

Maximum Pool Size: 32

Pool Resize Quantity: 2

Idle Timeout: 300

Max Wait Time: 60000

Connection Validation

Connection Validation: Required (checked)

Validation Method: table

Table Name: DUAL

On Any Failure: Close All Connections (unchecked)

Transaction Isolation

Transaction Isolation: read-committed

Isolation Level: Guaranteed (unchecked)

The problem only occurs when connection pool resource type is set to:

Resource Type: javax.sql.ConnectionPoolDataSource

Then, if i set the Transaction Isolation level to anything (other than default which is blank), I get the following error from appserver:

[#|2006-09-06T17:26:43.574-0400|SEVERE|sun-appserver-pe8.2|javax.enterprise.res ource.resourceadapter|_ThreadID=12;|jdbc.exc_tx_level|#]

[#|2006-09-06T17:26:43.576-0400|WARNING|sun-appserver-pe8.2|javax.enterprise.re source.resourceadapter|_ThreadID=12;|RAR5117 : Failed to obtain/create connection. Reason : The isolation level could not be set: Transaction isolation level NONE not supported by MySQL|#]

[#|2006-09-06T17:26:43.577-0400|WARNING|sun-appserver-pe8.2|javax.enterprise.re source.resourceadapter|_ThreadID=12;|RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: The isolation level could not be set: Transaction isolation level NONE not supported by MySQL]|#]

If i set the resource type to:

Resource Type: javax.sql.DataSource

I don't have this problem. I can set the Transaction Isolation level to whatever i want and get no warnings and everything appears to work correctly.

I initially thought the problem was with the MySQL Connector J driver. I posted to their support forum and got the following response:

<mysqlResponse>

Alan,

That's a very strange error, given that the only way you can get that exception is if something _outside_ our JDBC driver passes in Connection.TRANSACTION_ISOLATION_NONE to setTransactionIsolation()

(here's the code in question)

<pre>

switch (level) {

case java.sql.Connection.TRANSACTION_NONE:

throw SQLError.createSQLException("Transaction isolation level "

+ "NONE not supported by MySQL");

case java.sql.Connection.TRANSACTION_READ_COMMITTED:

sql = "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED";

break;

...

default:

throw SQLError.createSQLException("Unsupported transaction "

+ "isolation level '" + level + "'",

SQLError.SQL_STATE_DRIVER_NOT_CAPABLE);

}

</pre>

Given that ConnectionPoolDataSource isn't actually a pool (it's to be used by a connection pool), I'd look into if Sun's appserver can pool connections from a regular data source (most appservers can and [docs.sun.com] leads me to belive it does support this), or alternatively try and figure out what's passing the NONE transaction isolation level into Connector/J from inside SJAS, maybe it does this by default when you use a ConnectionPoolDataSource?.

I can't explain the difference in behavior via inspection of our code, since the connection that's returned from our ConnectionPoolDataSource is just a wrapper around our connection, and just does the following:

checkClosed();

try {

this.mc.setTransactionIsolation(level);

} catch (SQLException sqlException) {

checkAndFireConnectionError(sqlException);

}

We don't have many SJAS users who hang out here, have you tried asking on the Sun forums for SJAS, maybe this is a known issue over there? If you do find out something over there, let us know, and we'll see if there's anything that's fixable in our driver.

-Mark

Mark Matthews

MySQL AB, Software Development Manager - Client Connectivity

www.mysql.com

</mysqlResponse>

I really want to take advantage of connection pooling and must have the transaction isolation level be read-committed for the database sessions instantiated by the application. Does anyone have any ideas as to what I might be doing wrong?

thanks in advance for your guidance,

- Alan

[4892 byte] By [aoliverScripps] at [2007-11-26 11:04:27]
# 1

Hi Alan,

I am able to set the TxIsolationLevel without any issues.

- --

Connection conn1 = null;

boolean passed = false;

try {

conn1 = ds.getConnection();

System.out.println("Tx Isolation Level : " + conn1.getTransactionIsolation());

conn1.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);

} catch( Exception e) {

e.printStackTrace();

return false;

}finally{

try{

if(conn1 != null){

conn1.close();

}

}catch(Exception e){}

}

- --

Con Pool Settings :

Datasource : com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource

Resource Type: javax.sql.ConnectionPoolDataSource

Transaction Isolation: read-committed

Isolation Level: Guaranteed (unchecked)

- --

MySQL server : 5.0.22

connector J 3.x & 5.x

- --

1) Can you please provide the version (build no. ) of SJSAS ?

command : SJSAS_INSTALL_DIR/bin/asadmin version --verbose

2) Can you provide the code snippet that changes the isolation level ?

Thanks,

-Jagadish

JagadishPrasath at 2007-7-7 3:18:20 > top of Java-index,Application & Integration Servers,Application Servers...
# 2

Jagadish,

Thanks for your reply. I've answered your questions below...

1) SJSAS 8.2 build b06-fcs

2) I am not programmatically changing the isolation level. I've configured my connection pool to set the default transaction isolation level to read-committed (from the default of blank). With isolation set to read-committed (or anything other than default), if i uncheck the option "Isolation Level Guaranteed", whenever I try to utilize a connection from the connection pool, i get the error:

[#|2006-09-06T17:26:43.574-0400|SEVERE|sun-appserver-pe8.2|javax.enterprise.res ource.resourceadapter|_ThreadID=12;|jdbc.exc_tx_level|#]

[#|2006-09-06T17:26:43.576-0400|WARNING|sun-appserver-pe8.2|javax.enterprise.re source.resourceadapter|_ThreadID=12;|RAR5117 : Failed to obtain/create connection. Reason : The isolation level could not be set: Transaction isolation level NONE not supported by MySQL|#]

[#|2006-09-06T17:26:43.577-0400|WARNING|sun-appserver-pe8.2|javax.enterprise.re source.resourceadapter|_ThreadID=12;|RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: The isolation level could not be set: Transaction isolation level NONE not supported by MySQL]|#]

If i check the option "Isolation Level Guaranteed", the error goes away and I'm able to utilize connections from the connection pool.

Thanks in advance for your help,

- awo

aoliverScripps at 2007-7-7 3:18:20 > top of Java-index,Application & Integration Servers,Application Servers...
# 3

Its working fine for the following configuration :

SJSAS VERSION :

asadmin version --verbose

Version = Sun Java System Application Server Platform Edition 8.2 (build b06-fcs)

Command version executed successfully.

CON-POOL CONFIG:

<jdbc-connection-pool connection-validation-method="table" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSour ce" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="true" is-isolation-level-guaranteed="false" max-pool-size="32" max-wait-time-in-millis="60000" name="ql-jdbc-pool" pool-resize-quantity="2" res-type="javax.sql.ConnectionPoolDataSource" steady-pool-size="10" transaction-isolation-level="read-committed" validation-table-name="user">

<property name="User" value="jagadish"/>

<property name="Password" value="jagadish"/>

<property name="driverType" value="4"/>

<property name="portNumber" value="3306"/>

<property name="dataBaseName" value="mysql"/>

<property name="serverName" value="MYSQLSERVER"/>

<property name="URL" value="jdbc:mysql://MYSQLSERVER:3306/mysql"/>

</jdbc-connection-pool>

CODE :

try {

conn1 = ds.getConnection();

System.out.println("Tx Isolation Level : " + conn1.getTransactionIsolation());

} catch( Exception e) {

e.printStackTrace();

return false;

}finally{

try{

if(conn1 != null){

conn1.close();

}

}catch(Exception e){}

}

LOG :

[#|2006-11-03T11:20:29.729+0530|INFO|sun-appserver-pe8.2|javax.enterprise.syste m.stream.out|_ThreadID=11;|Tx Isolation Level : 2|#]

JagadishPrasath at 2007-7-7 3:18:20 > top of Java-index,Application & Integration Servers,Application Servers...