Hibernate configures Proxool to connect to Oracle 11g

Source: Internet
Author: User

Hibernate supports third-party connection pools. the officially recommended connection pools are C3P0, Proxool, and DBCP. Note the following three points when configuring the connection pool:

1. Apche's DBCP is supported in Hibernate2, but it is no longer recommended in Hibernate3. The official explanation is that this connection pool has defects. If you need to use DBCP in Hibernate3 for some reason, we recommend that you use the JNDI method.

2. By default (that is, if the connection pool is not configured), Hibernate uses the built-in connection pool. However, this connection pool has poor performance and many bugs. (the default value is used in the program connecting to the oralce database. As a result, if no operation is performed in one night, an error is reported that the connection has expired ), therefore, the official recommendation is only available in the development environment.

In addition, some foreign articles say that C3P0 has some defects in performance (its algorithm is not optimal), and Proxool is the one with the least negative comments.

If you really want to use C3P0, refer to the following method:

1. Add jar package -- c3p0-0.9.1.jar for the project

2. Add in hibernate. cfg. xml

<! -- C3P0 -->

<Property name = "hibernate. c3p0. max_size"> 30 </property> <! -- Maximum number of connections to all databases in the connection pool -->
<Property name = "hibernate. c3p0. min_size"> 2 </property> <! -The minimum number of available database connections in the connection pool -->
<Property name = "hibernate. c3p0. timeout"> 5000 </property> <! -Set the database connection timeout -->
<Property name = "hibernate. c3p0. max_statements"> 100 </property> <! -Maximum number of cached PreparedStatement -->
<Property name = "hibernate. c3p0. idle_test_period"> 3000 </property>
<Property name = "hibernate. c3p0. acquire_increment"> 2 </property>
<Property name = "hibernate. c3p0. validate"> false </property>
<Property name = "hibernate. c3p0. provider_class"> org. hibernate. connection. C3P0ConnectionProvider </property>
<Property name = "hibernate. show_ SQL"> true </property>


Complete these two steps.

We recommend that you use Proxool to configure the connection pool as follows:

1. Obtain proxool
Download and use the hibernate version compatible with the proxool-x.x.x.jar, the official website address is http://proxool.sourceforge.net/

2. Compile the proxool configuration file

In the same directory as hibernate. cfg. xml, create the file ProxoolConf. xml with the following content:

<? Xml version = "1.0" encoding = "UTF-8"?>
<! -- The proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<Something-else-entirely>
<Proxool>
<Alias> ServerPool </alias> <! -- The alias of the connection pool can be written at will, but note that it should be matched later in the hibernate section -->
<! -- Proxool can only manage connections generated by itself -->
<Driver-url> jdbc: Oracle: thin: @ 101.162.172.79: 1600: yytest </driver-url>
<Driver-class> oracle. jdbc. driver. OracleDriver </driver-class>
<Driver-properties>
<Property name = "user" value = "ttapp"/>
<Property name = "password" value = "ttapp"/>
</Driver-properties>
<! -- The proxool automatically detects the time interval (in milliseconds) of each connection status. When idle connections are detected, the system immediately recycles the connection status and destroys the connection timeout. -->
<House-keeping-sleep-time> 90000 <! -- Indicates the maximum number of requests waiting in the queue because no idle connections can be allocated. User connections exceeding the number of requests will not be accepted. -->
<Maximum-new-connections> 20 </maximum-new-connections>
<! -- Minimum number of idle connections maintained -->
<Prototype-count> 5 </prototype-count>
<! -- The maximum number of connections allowed. If the connection is exceeded, the requests are placed in the queue. the maximum number of waiting requests is determined by maximum-new-connections. -->
<Maximum-connection-count> 100 </maximum-connection-count>
<! -- Minimum connections -->
<Minimum-connection-count> 10 </minimum-connection-count>
</Proxool>
</Something-else-entirely>

Note: in actual use, it is best to remove the comment; otherwise, an error may be reported, as if I reported an error (Proxool Provider unable to load JAXP aggregator file: proxool. xml )..

Java Web Database Connection Pool proxool configuration details

Hibernate details: click here
Hibernate: click here

Hibernate Chinese manual PDF

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.