Bug #17401 XAConn.getConnection() should have behaviour of normal connection without TX
Submitted: 14 Feb 2006 21:29 Modified: 10 Mar 2006 20:29
Reporter: Sergey Vladimirov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.0.0-beta OS:Microsoft Windows (Windows XP)
Assigned to: CPU Architecture:Any

[14 Feb 2006 21:29] Sergey Vladimirov
Description:
Connection from XAConnection should have behaviour of normal connection outside of TX. User should be able to set autocommit mode, etc.

For example, this code should not throws exceptions:

    public void testXADataSourceWithoutTX() throws Exception {
        XADataSource dataSource = (XADataSource) Class.forName(
                "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource")
                .newInstance();
        dataSource.getClass().getMethod("setURL", new Class[] { String.class })
                .invoke(dataSource,
                        new Object[] { "jdbc:mysql://localhost/arpsite" });
        dataSource.getClass().getMethod("setLogger",
                new Class[] { String.class }).invoke(dataSource,
                new Object[] { "com.mysql.jdbc.log.StandardLogger" });

        XAConnection xaConnection = dataSource.getXAConnection("root", "");
        Connection connection = xaConnection.getConnection();
        connection.setAutoCommit(true); <---
        connection.close();
        xaConnection.close();
    }

Additional problems - the connection doesn't want to save any data, if there is not global transaction.

How to repeat:
Code from example should not throws exceptions.

Suggested fix:
Return normal connection from XA when XA Connection is not enlisted in TX.
[15 Feb 2006 22:06] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/2691
[18 Feb 2006 22:00] Sergey Vladimirov
Patch (night build) works!

Thanks!
[10 Mar 2006 20:29] Mark Matthews
Fix will be available in 5.0.1 and 3.1.13. You can try a nightly snapshot from http://downloads.mysql.com/snapshots.php#connector-j if you want to test the fix before it's officially released. Thanks for the bug report.