1
votes

Oracle is moving to Universal Connection Pool (UCP) for maintaining pooled connections that can be borrowed, returned or closed. My webapplication has this in place with its own data layer. This application will migrate to use JPA with Hibernate. At this point, I can only configure Hibernate to use the Oracle JDBC driver.

How can Hibernate be configured to use UCP?

There is documentation on how to use c3p0, but this does not work for UCP.

This is my Hibenate configuration with a JDBC connection without UCP:

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 
        <property name="hibernate.connection.url">jdbc:oracle:thin:@DBSERVER:1521:DATABASE</property> 
        <property name="hibernate.connection.username">username</property> 
        <property name="hibernate.connection.password">password</property> 
        <property name="dialect">org.hibernate.dialect.OracleDialect</property>
        ....
        <mapping resource="Country.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

These are my connection settings for UCP and JDBC for direct access without Hibernate:

PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setUser("username");
pds.setPassword("password");

pds.setConnectionFactoryProperty("driverType", "thin");
pds.setURL("jdbc:oracle:thin:@DBSERVER:1521:DATABASE");
pds.setInitialPoolSize(10);
pds.setMaxPoolSize(200);
1
So you're going to migrate to a pure JPA solution? The datasource will be JTA managed?André
That is correct: JPA solution with Hibernate as JPA provider.Dimitri Dewaele
Well, I don't think there is an answer that just works. My best bet would be to implement a custom ConnectionProvider, with the code you have above. But it really needs to use the UCP? A standard connection pool would suffice most use cases.André

1 Answers

3
votes

You will have to implement a ConnectionProvider to interface the OracleConnectionPool with Hibernate.

Here is an example of such implementation: https://forum.hibernate.org/viewtopic.php?p=2452561.