简体   繁体   中英

How to configure Hibernate with UCP

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);

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM