Hibernate不能即時擷取MySQL資料庫的更新,hibernatemysql

來源:互聯網
上載者:User

Hibernate不能即時擷取MySQL資料庫的更新,hibernatemysql

最近項目中使用到了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>

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

相關文章

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.