After a piece of data is inserted using hibernate, the database already exists and cannot be found in the app. After restarting tomcat, the app can query errors.

Source: Internet
Author: User

Today, I inserted a piece of data into my project. I thought this module was finally done. But I expected to see, "When I inserted a piece of data using hibernate, the database already exists and the app could not find it, after restarting tomcat, the app can query ".

At that time, my analysis was like this, because the database already exists and the Java program can be found after Tomcat is restarted, exclude uncommitted transactions (usually used for hibernate development because it is used to commit ). This may be because the session is not closed. The data obtained before Tomcat is closed is in the previous session, but the program code checks this assumption. I can see an introduction in this article. Now I will record it.

Add the following configuration in hibernate. cfg. XML (of course the corresponding jar should also be introduced, the version I use is c3p0-0.9.1.jar)

<Property name = "hibernate. Connection. provider_class"> org. hibernate. Connection. c3p0connectionprovider </property>

There will be other problems that cause this phenomenon, but I have used this method to solve my problem. If you still need to add it later. In addition, I did not continue to study this rack package. The role of this configuration should be noted down for future studies.

Note: This solution is found on the internet, but now the link address cannot be found, and it is recorded.



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.