Pregunta

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);
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top