1. hibernate default connection pool
<? XML version = '1. 0' encoding = 'utf-8'?>
<! Doctype hibernate-Configuration
Public "-// hibernate/hibernate configuration DTD // en"
Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
<Hibernate-configuration>
<Session-factory>
<!? JDBC driver -->
<Property name = "connection. driver_class"> com. MySQL. JDBC. Driver </property>
<! -- Connection URL -->
<Property name = "connection. url">
JDBC: mysql: // localhost: 3306/schoolproject
</Property>
<Property name = "connection. useunicode"> true </property>
<Property name = "connection. characterencoding"> UTF-8 </property>
<! -- Connection login name -->
<Property name = "connection. username"> root </property>
<!? Logon password -->
<Property name = "connection. Password"> </property>
<! -- Whether to output SQL statements generated during runtime to logs for debugging -->
<Property name = "show_ SQL"> true </property>
<! -- Specify the connection language -->
<Property name = "dialect"> org. hibernate. dialect. mysqldialect </property>
<! -- Map the Student Resource -->
<Mapping Resource = "com/wqbi/model/pojo/student. HBM. xml"/>
</Session-factory>
</Hibernate-configuration>
2. c3p0 connection Configuration
<? XML version = '1. 0' encoding = 'utf-8'?>
<! Doctype hibernate-Configuration
Public "-// hibernate/hibernate configuration DTD // en"
Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
<Hibernate-configuration>
<Session-factory>
<!? JDBC driver -->
<Property name = "connection. driver_class"> com. MySQL. JDBC. Driver </property>
<! -- Connection URL -->
<Property name = "connection. url">
JDBC: mysql: // localhost: 3306/schoolproject
</Property>
<Property name = "connection. useunicode"> true </property>
<Property name = "connection. characterencoding"> UTF-8 </property>
<! -- Connection login name -->
<Property name = "connection. username"> root </property>
<! -- Logon password -->
<Property name = "connection. Password"> </property>
<! -- C3p0 connection pool settings -->
<Property name = "hibernate. Connection. provider_class"> org. hibernate. Connection. c3p0connectionprovider
</Property>
<Property name = "hibernate. c3p0. max_size"> 20 </property>
<Property name = "hibernate. c3p0. min_size"> 5 </property>
<Property name = "hibernate. c3p0. Timeout"> 120 </property>
<Property name = "hibernate. c3p0. max_statements"> 100 </property>
<Property name = "hibernate. c3p0. idle_test_period"> 120 </property>
<Property name = "hibernate. c3p0. acquire_increment"> 2 </property>
<! -- Whether to output SQL statements generated during runtime to logs for debugging -->
<Property name = "show_ SQL"> true </property>
<! -- Specify the connection language -->
<Property name = "dialect"> org. hibernate. dialect. mysqldialect </property>
<! -- Map the Student Resource -->
<Mapping Resource = "com/wqbi/model/pojo/student. HBM. xml"/>
</Session-factory>
</Hibernate-configuration>
3. proxool connection pool
(1) first write the proxool configuration file, file name: proxool. XML (usually with hibernate. cfg. in this example, the MySQL database is configured and the database name is schoolproject.
<? 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 of the connection pool -->
<Alias> dbpool </alias>
<! -- Proxool can only manage connections generated by itself -->
<Driver-URL>
JDBC: mysql: // localhost: 3306/schoolproject? Useunicode = true & characterencoding = utf8
</Driver-URL>
<!? JDBC driver -->
<Driver-class> com. MySQL. JDBC. Driver </driver-class>
<Driver-Properties>
<Property name = "user" value = "root"/>
<Property name = "password" value = ""/>
</Driver-Properties>
<! -- The proxool automatically detects the time interval (in milliseconds) of each connection status, and returns immediately after detecting idle connections.
Receive and destroy timeout -->
<House-keeping-sleep-time> 90000
<! -- The maximum number of requests waiting in the queue because no idle connections can be allocated.
User connection 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 this connection is exceeded and another request is made, the connections are waiting in the queue.
The number of pending 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>
(2) configure the hibernate. cfg. xml file
<? XML version = '1. 0' encoding = 'utf-8'?>
<! Doctype hibernate-Configuration
Public "-// hibernate/hibernate configuration DTD // en"
Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
<Hibernate-configuration>
<Session-factory>
<Property name = "hibernate. Connection. provider_class">
Org. hibernate. Connection. proxoolconnectionprovider
</Property>
<Property name = "hibernate. proxool. pool_alias"> dbpool </property>
<Property name = "hibernate. proxool. xml"> proxoolconf. xml </property>
<! -- Whether to output SQL statements generated during runtime to logs for debugging -->
<Property name = "show_ SQL"> true </property>
<! -- Specify the connection language -->
<Property name = "dialect"> org. hibernate. dialect. mysqldialect </property>
<! -- Map the Student Resource -->
<Mapping Resource = "com/wqbi/model/pojo/student. HBM. xml"/>
</Session-factory>
</Hibernate-configuration>
(1) hibernate. Connection. provider_class defines the hibernate connection loading class. Here, the proxool connection pool uses this class. Different connection pools have different loading classes. You can refer to the hibernate documentation to obtain relevant information.
(2) hibernate. proxool. pool_alias here is the alias of the connection pool we mentioned above.
(3) hibernate. proxool. xml declares the location of the configuration file for the connection pool to hibernate. You can use relative or absolute paths. When using relative paths, be sure to be within the path range! Otherwise, an exception is thrown.
(4) dialect is the dialect for declaring SQL statements.
(5) show_ SQL defines whether to display the SQL language generated by hibernate. It is generally set to true in the debugging phase and then changed to false after completion, which is conducive to debugging.
(6) <mapping> resource file ing
4. The JNDI connection pool. The data source has been configured by the Application Service (such as the Web server). What hibernate needs to do is to find the data source through the JNDI name. The application server displays the external connection pool as a JNDI bound data source. It is an instance of the javax. JDBC. datasource class. You only need to configure a hibernate file, such:
Hibernate. Connection. datasource = Java:/COMP/ENV/jdbc/schoolproject // JNDI name
Hibernate. transaction. factory_class = org. hibernate. transaction. jtatransactionfactory
Hibernate. transaction. manager_loopup_class =
Org. hibernate. transaction. jbosstransactionmanagerlookup
Hibernate. dialect = org. hibernate. dialect. mysqldialect