Spring Boot 1.2.7,Hibernate和Oracle UCP

时间:2015-11-08 20:09:05

标签: spring oracle hibernate spring-jdbc ucp

我正在尝试使用Hibernate配置Oracle UCP以在我的Spring Boot 1.2.7应用程序中工作。我目前有c3p0工作,但我需要支持Oracle RAC。

我意识到Hibernate没有直接支持Oracle UCP,但是来自Oracle的这个文档似乎说我可以使用它:

https://blogs.oracle.com/dev2dev/entry/how_to_use_oracle_universal

此外,我发现了一些较旧的示例,演示了如何创建Bean和/或使用XML进行配置,但我目前没有XML配置。此外,我认为Spring,此时可以从application.properties文件和pom中完成所有操作。

在我的pom中,对于Oracle,我有:

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc7</artifactId>
        <version>12.1.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ucp</artifactId>
        <version>12.1.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ons</artifactId>
        <version>12.1.0.2</version>
    </dependency>

对于Hibernate,我有:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.3.Final</version>
    </dependency>           
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>4.3.11.Final</version>
    </dependency>

我意识到我可以删除c3p0的依赖性。

我感到困惑的是要指定的属性。我想我需要这些:

spring.datasource.driverClassName=oracle.jdbc.pool.OracleDataSource
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.connection.driver_class = oracle.jdbc.pool.OracleDataSource
spring.datasource.url=jdbc:oracle:thin:@mydb.mycomp.com:1521:abcde
spring.datasource.username=user
spring.datasource.password=pass
spring.jpa.properties.hibernate.connection.username=user
spring.jpa.properties.hibernate.connection.password=pass
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.connection.provider_class = oracle.jdbc.pool.OracleDataSource
spring.datasource.maxPoolSize = 10
spring.datasource.initialPoolSize = 5

当我解雇时,我得到:

java.sql.SQLException: oracle.jdbc.pool.OracleDataSource cannot be cast to java.sql.Driver
    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:280)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:200)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:708)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:642)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:464)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:141)

如果有人可以让我知道正确的属性或指向我当前的文档,我将非常感谢,谢谢!

0 个答案:

没有答案