Home > Database > Mysql Tutorial > body text

Hibernate不能实时获取MySQL数据库的更新_MySQL

WBOY
Release: 2016-06-01 13:04:22
Original
1567 people have browsed it

最近项目中使用到了Hibernate,但每次数据库记录有更新后,用hibernate无法查找到更新后的数据。网上查找了许多教程,最终发现通过更改hibernate的默认连接池可以解决。通过使用c3p0连接池,替换掉hibernate的默认连接池后,就可以查找到MySQL更新后的数据了。

具体修改方法如下:

在hibernate.cfg.xml配置文件中,增加以下内容:

 <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.max_statements">100</property>
                <property name="hibernate.c3p0.idle_test_period">120</property>
                <property name="hibernate.c3p0.acquire_increment">1</property>
                <property name="c3p0.testConnectionOnCheckout">true</property>
                <property name="c3p0.idleConnectionTestPeriod">18000</property>
                <property name="c3p0.maxIdleTime">25000</property>
Copy after login

附上c3p0的jar包,下载地址:http://download.csdn.net/detail/until_v/8149191

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!