Hibernate cannot get the updated records in the database in real time solve the problem

Source: Internet
Author: User
Tags tomcat server

The project uses Hibernate to connect and manipulate the MySQL database, with a "query" module and a "Add" module, which are made with different hibernate profiles. After the addition after the completion of the query found the problem, the results of the query is always added before, and the latest updated records are not queried. Only restart the Tomcat server to find the updated records.

Google's.

The cache mechanism of hibernate is mentioned on the Internet, http://blog.csdn.net/fjun0910/article/details/6092829

According to it, use Session.clear () before the query, clear the first-level cache, retry adding + queries, or you cannot find the update record. Use Setcachemode (Cachemode.ignore) to clear level two cache, experiment, failure. Two are cleared and still fail.

Is confused, found here: http://blog.sina.com.cn/s/blog_6d818993010137in.html

Although not very clear, but found the problem: Hibernate default Connection pool problems, using the C3P0 connection pool can be. As a result, the following steps are used to resolve the problem:

First add the required jar package: Hibernate-c3p0-4.2.0.final.jar,c3p0-0.9.2.1.jar,mchange-commons-java-0.2.7.jar, can be distributed to/HTTP mvnrepository.com/and http://www.java2s.com/Download, note Mchange-commons-java version not too low, otherwise it will classnotfound wrong.

Modify the Hibernate configuration file, connect to the database with the C3P0 connection pool, and add the following configuration outside of the previous configuration:

<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= "AutomaticTestTable" >test</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>

Solve the problem.

Above.

This article is from the "Wood on the Road" blog, please be sure to keep this source http://mumufairy.blog.51cto.com/6184508/1551220

Hibernate cannot get the updated records in the database in real time solve the problem

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.