Configuration of c3p0 in hibernate

Source: Internet
Author: User

The following configurations are available in hibernate. cfg. xml.
<Property name = "hibernate. Connection. provider_class"> org. hibernate. Connection. c3p0connectionprovider </property> perty name = "hibernate. c3p0. acquireretryattempts"> 30 </property>
<Property name = "hibernate. c3p0. acquireincrement"> 2 </property>
<Property name = "hibernate. c3p0. checkouttimeout"> 30000 </property>
<Property name = "hibernate. c3p0. idleconnectiontestperiod"> 120 </property>
<Property name = "hibernate. c3p0. maxidletime"> 180 </property>
<Property name = "hibernate. c3p0. initialpoolsize"> 3 </property>
<Property name = "hibernate. c3p0. maxpoolsize"> 50 </property>
<Property name = "hibernate. c3p0. minpoolsize"> 1 </property>
<Property name = "hibernate. c3p0. maxstatements"> 0 </property>

Then, the number of connections with initialpoolsize = 3 will be created each time during use. If you refresh multiple times, the too connector CTS error is reported. I have been surfing the internet for a long time and I don't know why. Only one similar problem description is found on javaeye.
Later, I read the official documents of c3p0 to find the reason.
Solution: delete this configuration! Because it cannot be configured here. If necessary, you can configure it through the c3p0 configuration file.
Official documentation:

C3p0-native property name Hibernate configuration key
C3p0. acquireincrement Hibernate. c3p0. acquire_increment
C3p0. idleconnectiontestperiod Hibernate. c3p0. idle_test_period
C3p0. initialpoolsize Not available -- uses minimum size
C3p0. maxidletime Hibernate. c3p0. Timeout
C3p0. maxpoolsize Hibernate. c3p0. max_size
C3p0. maxstatements Hibernate. c3p0. max_statements
C3p0. minpoolsize Hibernate. c3p0. min_size
C3p0. testconnectionsoncheckout Hibernate. c3p0. Validate
Hibernate 2.x only!

Remember --
These, andOnly these, Properties must be defined in your hibernate configuration,
Or else they will be set to hibernate-specified defaults. All other configuration properties that you wish to set shoshould be defined in
C3p0. PropertiesFile. (See
"Overriding c3p0 defaults via c3p0. properties ".)

Note:

1. C3p0. initialpoolsize Not available -- uses minimum size

Note: This configuration cannot be configured in hibernate. It uses minpoolsize.
2.These, andOnly these, Properties must be defined in your hibernate configuration,
In hibernateOnly and requiredConfigure these attributes.

Many configuration documents provided on the Internet are incorrect or nonstandard! No one raised this question for some reason. It is estimated that it was copied.
In addition, the following statements are incorrect when you configure these attributes in hibernate! Or non-standard.
<Property name = "hibernate. c3p0. acquireretryattempts"> 30 </property>
<Property name = "hibernate. c3p0. acquireincrement"> 2 </property>
<Property name = "hibernate. c3p0. idleconnectiontestperiod"> 120 </property>
<Property name = "hibernate. c3p0. maxidletime"> 180 </property>
<Property name = "hibernate. c3p0. maxpoolsize"> 50 </property>
<Property name = "hibernate. c3p0. minpoolsize"> 1 </property>
<Property name = "hibernate. c3p0. maxstatements"> 0 </property>
After testing, three connections are created for each query. Why? Initialization is not configured hereInitialpoolsizeValue?
Initialpoolsize
The default value is 3, so three connections are created each time? This is probably the problem.

Therefore, it is well-behaved to use official writing. As to why the number of initialization will be created each time (or the number will be initialized once every query), it is unclear whether it is a problem with my code or cp30 .) Have time to investigate.

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.