如何同时使用SQLExceptionTranslator和Oracle UCP

zkure5ic  于 2023-11-17  发布在  Oracle
关注(0)|答案(1)|浏览(152)

我使用Oracle UCP作为连接池驱动程序。我尝试在我的JdbcTemplate中使用SQLExceptionTranslator,但有一个问题。当我用重写的customTranslate()实现我自己的SqlExceptionTranslator实现时,如果数据库端有异常,我会有以下情况:

...java.sql.SQLException: Exception occurred while getting connection: oracle.ucp.UniversalConnectionPoolException: Universal Connection Pool internal error: **java.lang.ClassCastException: class oracle.ucp.UniversalConnectionPoolException cannot be cast to class java.sql.SQLException** (oracle.ucp.UniversalConnectionPoolException is in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @6f496d9f; java.sql.SQLException is in module java.sql of loader 'platform')
            at oracle.ucp.util.UCPErrorHandler.newSQLException(UCPErrorHandler.java:498) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.util.UCPErrorHandler.throwSQLException(UCPErrorHandler.java:175) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1899) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.access$300(PoolDataSourceImpl.java:224) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl$3.build(PoolDataSourceImpl.java:4050) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1822) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1778) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1764) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            ... 33 more
    Caused by: oracle.ucp.UniversalConnectionPoolException: Universal Connection Pool internal error: java.lang.ClassCastException: class oracle.ucp.UniversalConnectionPoolException cannot be cast to class java.sql.SQLException (oracle.ucp.UniversalConnectionPoolException is in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @6f496d9f; java.sql.SQLException is in module java.sql of loader 'platform')
            at oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:378) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:68) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:91) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:164) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.Core.growBorrowed(Core.java:1289) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.helpGrowBorrowed(UniversalConnectionPoolImpl.java:406) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionWithoutCountingRequests(UniversalConnectionPoolImpl.java:349) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionAndValidateHelper(UniversalConnectionPoolImpl.java:205) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionAndValidate(UniversalConnectionPoolImpl.java:165) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnection(UniversalConnectionPoolImpl.java:138) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.JDBCConnectionPool.borrowConnection(JDBCConnectionPool.java:184) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.borrowConnection(OracleJDBCConnectionPool.java:610) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.oracle.OracleConnectionConnectionPool.borrowConnection(OracleConnectionConnectionPool.java:118) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1879) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.access$300(PoolDataSourceImpl.java:224) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl$3.build(PoolDataSourceImpl.java:4050) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1822) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1778) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1764) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            ... 33 more
    Caused by: java.lang.ClassCastException: class oracle.ucp.UniversalConnectionPoolException cannot be cast to class java.sql.SQLException (oracle.ucp.UniversalConnectionPoolException is in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @6f496d9f; java.sql.SQLException is in module java.sql of loader 'platform')
            at oracle.ucp.common.Service.create(Service.java:897) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.Service.create(Service.java:644) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.Topology.create(Topology.java:163) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.Core.growBorrowed(Core.java:1279) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.helpGrowBorrowed(UniversalConnectionPoolImpl.java:406) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionWithoutCountingRequests(UniversalConnectionPoolImpl.java:349) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionAndValidateHelper(UniversalConnectionPoolImpl.java:205) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionAndValidate(UniversalConnectionPoolImpl.java:165) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnection(UniversalConnectionPoolImpl.java:138) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.JDBCConnectionPool.borrowConnection(JDBCConnectionPool.java:184) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.borrowConnection(OracleJDBCConnectionPool.java:610) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.oracle.OracleConnectionConnectionPool.borrowConnection(OracleConnectionConnectionPool.java:118) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1879) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.access$300(PoolDataSourceImpl.java:224) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl$3.build(PoolDataSourceImpl.java:4050) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1822) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1778) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1764) ~[ucp-21.8.0.0.jar!/:21.8.0.0.0]
            at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-6.0.4.jar!/:6.0.4]
            ... 33 more

字符串
我认为原因是oracle.ucp.UniversalConnectionPoolException扩展了java.lang.Exception -一个customTranslate覆盖的方法需要java. sql. SQLEception。
但是,如何在Oracle UCP中使用SQLExceptionTranslator/jdbcTemplate.setExceptionTranslator功能?
问候
Koli

nukf8bse

nukf8bse1#

这是最近版本中修复的错误。您使用的是哪个UCP版本?如果您的版本中未修复,请提交Oracle支持服务请求以获取一次性修补程序。

相关问题