[Original]java Web Learning Note 80:hibernate Learning Path---Hibernate profile: JDBC connection properties, C3P0 database connection pool properties, etc.

Source: Internet
Author: User
Tags bulk insert java web

The purpose of this blog: ① summary of their own learning process, equivalent to study notes ② to share their own experience to everyone, learn from each other, communication, not commercialcontent inevitably appear problems, welcome to correct, exchange, discussion, you can leave a message, can also be contacted by the following ways. I Internet technology enthusiasts, Internet technology enthusiastsWeibo: Ivan is in 0221qq:951226918

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- -----------------------------

1.hibernate configuration file (partial reference http://www.cnblogs.com/jasonHome/p/5929471.html)

1) Hibernate profile is primarily used to configure the various properties required for database connection and Hibernate runtime

2) Each Hibernate profile corresponds to a configuration object

3) Hibernate configuration files can be in two formats:

Hibernate.properties

Hibernate.cfg.xml

Common Properties of 2.hibernate.cfg.xml

①JDBC Connection Properties

>connection.url: Database URL

>connection.username: Database user name

>connection.password: Database user password

>connection.driver_class: Database JDBC Driver

>dialect: The dialect of the configuration database, which produces different SQL statements depending on the underlying database, Hibernate optimizes access for database features

②C3P0 Database Connection Pool Properties

>hibernate.c3p0.max_size: The maximum number of connections for the database connection pool. Current application has high concurrency, large concurrency

>hibernate.c3p0.min_size: The minimum number of connections for the database connection pool. The current application does not have any requests, any concurrency, the minimum number of connections in the connection pool

>hibernate.c3p0.acquire_increment: How many database connections are fetched at the same time when the connection in the database connection pool is exhausted. How many database connections are made to the server each time a connection in the connection pool does not

    

>hibernate.c3p0.timeout: The Connection object in the database connection pool should be destroyed if it has not been used for a long time.

>hibernate.c3p0.idle_test_period: Indicates how long the connection pool detection thread is detecting whether all linked objects within the pool have timed out. The connection pool itself does not remove itself from the connection pool, but rather a thread that does it at certain intervals by comparing the last time the connection object was used and the current time to timeout, and then deciding whether to destroy the connection object.

    

>hibernate.c3p0.max_statements: The number of cached Statement objects.

③ Other

>show_sql: Whether to output the SQL generated by the run-time to the log for debugging. Value TRUE | False

>format_sql: Whether to convert SQL to well-formed SQL. Value TRUE | False

>hbm2ddl.auto: Automatically create, update, or delete database schemas when starting and stopping. Value Create | Update | Create-drop | Validate

>hibernate.jdbc.fetch_size:

1 hibernate.jdbc.fetch_size: Essentially, call the Statement.setfetchsize () method to set the number of records fetched from the database each time the JDBC Statement reads the data .
2 For example, a query 10,000 records, for the JDBC driver of Oracle, is not 1 times to take 10,000 out of the fetchsize, and only take out the number of entries, when the result set traversed these records, then go to the database to take Fetchsize data. Therefore, the unnecessary memory consumption is greatly saved.

Fetch size Sets the larger the number of times the database is read, and the faster the fetch size, the more times the database is read, the slower the speed.
   The default fetch Size = 10 for the JDBC drive of the Oracle database is a conservative setting that, depending on the test, will increase performance by 1 time times when fetch size=50, and when fetchsize=100, performance can continue to increase by 20%, Fetch size continues to grow, and the performance gains are not significant.
Not all databases support the fetch size feature, such as MySQL does not support

>hibernate.jdbc.batch_size:

1 hibernate.jdbc.batch_size: Sets the batch size for bulk delete , batch update and BULK INSERT, similar to the meaning of setting buffer size. The larger the batchsize, the lower the number of times a batch operation sends SQL to the database, the faster it becomes.  2 test result is that when batch size=0, using hibernate to delete 10,000 records for Oracle database takes 25 seconds, Batch Size = 50, delete only need 5 seconds! Oracle Database batchsize=30 is the right time .

    

   

1 <!--invalid for MySQL, valid for Oracle -2         <!--sets the number of records to be fetched from the database each time the JDBC statement reads data -3         < Propertyname= "Hibernate.jdbc.fetch_size">100</ Property>4         5         <!--set the size of the database for bulk Delete, batch update and BULK INSERT -6         < Propertyname= "Hibernate.jdbc.batch_size">30</ Property>

Configuring C3P0 data Sources in 3.hibernate

1) Import the jar package:

\ssh-framwork\hibernate-release-4.2.4.final\hibernate-release-4.2.4.final\lib\optional\c3p0\*

    

2) Add configuration:

1 <!--Configure C3P0 -2         < Propertyname= "Hibernate.c3p0.max_size">10</ Property>3         < Propertyname= "Hibernate.c3p0.min_size">5</ Property>4         < Propertyname= "C3p0.acquire_increment">2</ Property>5         < Propertyname= "C3p0.idle_test_period">2000</ Property>6         < Propertyname= "C3p0.timeout">2000</ Property>7         < Propertyname= "C3p0.max_statements">10</ Property>

[Original]java Web Learning Note 80:hibernate Learning Path---Hibernate profile: JDBC connection properties, C3P0 database connection pool properties, etc.

Related Article

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.