Hibernate娌℃湁鑷姩閲嶆柊杩炴帴鏁版嵁搴擄紝鍘熷洜寰堝彲鑳芥槸鍥犱负浣犱娇鐢ㄤ簡Hibernate鍐呯疆鐨勮繛鎺ユ睜锛岃繖涓繛鎺ユ睜涓嶄細鑷姩閲嶆柊杩炴帴銆備娇鐢∕ysql鏃讹紝榛樿杩8灏忔椂娌℃湁鏁版嵁浜ゆ崲锛孧ysql灏变細鍗曟柟闈㈡柇寮鏁版嵁搴撹繛鎺ワ紝鎵浠ユ湁浜涙椂鍊欎綘浼氬彂鐜拌繃浜8灏忔椂锛堟垨鑰呬竴鏅氫笂锛夊啀璁块棶缃戠珯锛岀▼搴忓氨浼氭姏鍑烘暟鎹簱閾炬帴閿欒锛岃岄噸鍚湇鍔″櫒瀹瑰櫒锛圱omcat绛夛級涔嬪悗绋嬪簭鍙堟仮澶嶆甯搞
缁嗗績鐨勪綘搴旇浼氬彂鐜帮紝濡傛灉浣跨敤榛樿鐨勮繛鎺ユ睜锛屽湪Hibernate鐨勬棩蹇楄褰曪紙INFO绾у埆锛変腑浼氭彁绀猴細Using Hibernate built-in connection pool (not for production use!)锛“浣犵幇鍦ㄤ娇鐢ㄧ殑鏄疕ibernate鍐呯疆鐨勮繛鎺ユ睜锛岃涓嶈鍦ㄤ骇鍝佷腑浣跨敤瀹冿紒”锛夊鏋滀綘涓嶅惉鍔濆憡锛屼粛鐒朵娇鐢ㄥ畠锛屽氨浼氬嚭鐜颁笂闈㈡墍璇寸殑鏁版嵁搴撳崟鏂归潰鏂紑杩炴帴鑰屾棤娉曡闂殑闂銆
瑙e喅姝ゆ柟娉曞氨鏄娇鐢ㄥ叾浠栫殑杩炴帴姹狅紝姣斿姝3p0锛屽湪Hibernate瀹樼綉鐨勫弬鑰冩墜鍐岋紙reference锛夌殑3.3鑺備腑鏈夌畝鍗曠殑浠嬬粛鈶狅細
/**********寮曠敤寮濮*********/
Hibernate's own connection pooling algorithm is however quite rudimentary. It is intended to help you get started and is not intended for use in a production system or even for performance testing. You should use a third party pool for best performance and stability. Just replace the hibernate.connection.pool_size property with connection pool specific settings. This will turn off Hibernate's internal pool. For example, you might like to use C3P0.
C3P0 is an open source JDBC connection pool distributed along with Hibernate in the lib directory. Hibernate will use its org.hibernate.connection.C3P0ConnectionProvider for connection pooling if you set hibernate.c3p0.* properties. If you'd like to use Proxool refer to the packaged hibernate.properties and the Hibernate web site for more information.
Here is an example hibernate.properties file for C3P0:
hibernate.connection.driver_class = org.postgresql.Driverhibernate.connection.url = jdbc:postgresql://localhost/mydatabasehibernate.connection.username = myuserhibernate.connection.password = secrethibernate.c3p0.min_size=5hibernate.c3p0.max_size=20hibernate.c3p0.timeout=1800hibernate.c3p0.max_statements=50hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
/**********寮曠敤缁撴潫*********/
鍒拌繖閲岃繕娌$粨鏉燂紝濡傛灉浣犳寜涓婇潰鐨勬柟娉曟坊鍔犱簡锛屼笉涓瀹氬彲浠ユ垚鍔熶娇鐢╟3p0杩炴帴姹狅紙鑷冲皯鎴戞祴璇曟椂娌℃湁鎴愬姛锛夛紝浣犺繕闇瑕佹坊鍔犱竴鍙ヨ瘽锛
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
瀹樻柟鍙傝冩枃妗f寚鍑篶onnection.provider_class灞炴ф槸鍦ㄨ嚜瀹氫箟杩炴帴鎻愪緵鑰呮椂浣跨敤鐨勶紝骞舵病鏈夎浣跨敤c3p0鏃朵篃瑕佸姞杩欏彞璇濄備絾鎴戞祴璇曟椂涓嶅姞杩欏彞璇濆氨娌℃湁鏁堟灉锛屾墍浠ヨ繕鏄姞涓婂惂锛
瀹屾暣鐨勮缃柟娉曪細
锛堝睘鎬ф枃浠讹級
/*************鎺掔増寮濮**************/
# Database connection settings
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/mydb
hibernate.connection.username=username
hibernate.connection.password=password
# configuration pool
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=15
hibernate.c3p0.timeout=3600
hibernate.c3p0.max_statements=50
# SQL dialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect
# Enable Hibernate's automatic session context management
hibernate.current_session_context_class=thread
# Echo all executed SQL to stdout
hibernate.show_sql=true
# Drop and re-create the database schema on startup
hibernate.hbm2ddl.auto=update
/*************鎺掔増缁撴潫**************/
濡傛灉浣犳兂鎶妏roperties鏀惧埌xml涓紝浣跨敤hibernate.c3p0.min_size绛4椤癸紝锛堣屼笉鏄痗3p0.min_size锛変笉鐒跺彲鑳戒細鎵斿嚭璀﹀憡銆
/*********鎺掔増寮濮***********/
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">15</property>
<property name="hibernate.c3p0.timeout">3600</property> <!-- seconds -->
<property name="hibernate.c3p0.max_statements">50</property>
/**********鎺掔増缁撴潫****************/
鍏充簬鏇村c3p0鐨勭敤娉曡浣犺嚜宸卞埌缃戜笂鎼滅储鍚э紒杩欓噷涓嶅啀閲嶈堪銆
娉ㄩ噴锛
鈶犲紩鐢ㄧ殑鍑哄锛2008骞9鏈10鏃 18:26:56淇敼鐗堬級锛http://docs.jboss.org/hibernate/stable/core/reference/en/html/configuration-hibernatejdbc.html