Java 8升级后无法获得数据库连接

时间:2015-11-12 16:11:45

标签: java hibernate jdbc ojdbc

我最近将应用程序从java 1.7升级到1.8。其余的库版本保持不变。升级后我收到以下错误:

DEBUG 2015-11-12 09:55:12 BasicResourcePool         An exception occurred while acquiring a poolable resource. Will retry.
java.lang.NullPointerException
    at oracle.net.jndi.JndiAttrs.getAttrs(JndiAttrs.java:207)
    at oracle.net.resolver.AddrResolution.<init>(AddrResolution.java:198)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:219)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

休眠配置:

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@ldaps://XXXX,cn=OOOO,dc=WWW</property>
        <property name="hibernate.connection.username">YYYY</property>
        <property name="hibernate.statement_cache.size">0</property>
        <property name="hibernate.connection.password">ZZZZZ</property>
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.timeout">1800</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.default_schema">YYYY</property>
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
        <property name="hibernate.show_sql">true</property>
    </session-factory>
</hibernate-configuration>

使用的相关库:

  • ojdbc6 11.2.0.3.0
  • hibernate 3.1

问题: 依赖项包含2个hibernate版本3.1和3.0以及ojdbc6和ojdbc7。 (使用mvn dependency:tree -Dverbose获取依赖树)

解决方案: 从依赖项中排除了其他版本的hibernate和ojdbc。

            <dependency>
                <groupId>****</groupId>
                <artifactId>****</artifactId>
                <version>****</version>
                <exclusions>
                    <exclusion>
                        <groupId>hibernate</groupId>
                        <artifactId>hibernate</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc6</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

1 个答案:

答案 0 :(得分:3)

正如我在Oracle FAQ中看到的那样,您使用的jdbc驱动程序与数据库版本和JDK8不兼容。

  

支持的各种受支持的Oracle数据库版本与JDBC兼容版本有哪些?   enter image description here

我认为这一定是你的问题。也许如果你使用ojdbc7.jar可能会有所帮助(不确定这个原因我还没有测试过它 - 最可能的,这可能会失败)