{"record":{"id":"7edd04fa1ed8f1aa","repo":"alibaba/druid","slug":"not-supported-by-druiddatasource-7edd04","errorCode":null,"errorMessage":"Not supported by DruidDataSource","messagePattern":"Not supported by DruidDataSource","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/druid/pool/xa/DruidXADataSource.java","lineNumber":99,"sourceCode":"                return PGUtils.createXAConnection(physicalConn);\n            case h2:\n                return H2Utils.createXAConnection(h2Factory, physicalConn);\n            case jtds:\n                return new JtdsXAConnection(physicalConn);\n            case dm:\n                return new DmdbXAConnection(physicalConn);\n            case oceanbase:\n            case oceanbase_oracle:\n                return new OceanBaseXaConnection((OceanBaseConnection) physicalConn);\n            default:\n                throw new SQLException(\"xa not support dbType : \" + this.dbTypeName);\n\n        }\n    }\n\n    @Override\n    public XAConnection getXAConnection(String user, String password) throws SQLException {\n        throw new UnsupportedOperationException(\"Not supported by DruidDataSource\");\n    }\n\n}\n","sourceCodeStart":81,"sourceCodeEnd":103,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/pool/xa/DruidXADataSource.java#L81-L103","documentation":"DruidXADataSource.getXAConnection(String user, String password) is deliberately unimplemented — it always throws UnsupportedOperationException. DruidXADataSource builds XA connections from its pooled physical connections, and the pool is initialized with a single fixed credential set; per-call credential XA connections are not supported. Use the no-arg getXAConnection().","triggerScenarios":"Calling druidXADataSource.getXAConnection(user, password) directly, or via a JTA/XA framework that resolves per-subject credentials and invokes the two-argument XA method.","commonSituations":"App-server managed XA with per-user credentials; migrating from a vendor XADataSource (which supports the two-arg form) to DruidXADataSource without removing the per-call credentials; XAResource recovery code that reconnects with explicit credentials.","solutions":["Use the no-arg getXAConnection() and configure username/password on the DruidXADataSource itself.","If per-user XA connections are required, use the database vendor's native XADataSource instead of DruidXADataSource.","Check your transaction manager / connection manager configuration to ensure it calls the no-arg variant."],"exampleFix":"// before\nXAConnection xa = druidXaDataSource.getXAConnection(\"alice\", \"pw\"); // throws\n\n// after\ndruidXaDataSource.setUsername(\"alice\");\ndruidXaDataSource.setPassword(\"pw\");\ndruidXaDataSource.init();\nXAConnection xa = druidXaDataSource.getXAConnection();","handlingStrategy":"validation","validationCode":"// never call getXAConnection(user, pwd) on DruidXADataSource;\n// set credentials on the datasource itself.\nif (ds instanceof DruidXADataSource) {\n    throw new IllegalArgumentException(\"DruidXADataSource only supports the no-arg getXAConnection()\");\n}","typeGuard":"public static boolean supportsCredentialedXA(DataSource ds) {\n    return !(ds instanceof DruidXADataSource);\n}","tryCatchPattern":"try {\n    xa = ((XADataSource) ds).getXAConnection(user, pass);\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().contains(\"DruidDataSource\")) {\n        xa = ((XADataSource) ds).getXAConnection();\n    } else throw e;\n}","preventionTips":["Configure username/password on the DruidXADataSource, not per XA call.","If per-user XA is needed, use the vendor XADataSource instead.","Check your transaction manager to ensure it calls the no-arg XA variant."],"tags":["xa","unsupported-operation","authentication","jdbc"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}