Spring Webflow + Jpa + Hibernate run-time non-responsive problem handling

Source: Internet
Author: User

Problem phenomenon:

Pages that use the spring Webflow process need to query data from MySQL, show up in the foreground, and the page will not respond after several queries, and the last of the server's logs is Hibernate's SQL statement.

Operating Environment:

jre:1.8

Spring Framework:4.3.8.release

Spring Webflow:2.4.5.release

Spring Data Jpa:1.11.4.release

Hibernate:5.2.5.final

mysql:5.7.14

tomcat:8.0 (database connection pool using Tomcat)

Problem Solving Process:

1. Suspect database deadlock

The development environment has only one user, and the actions of these pages are only queried, and the log query with MySQL Workbench is normal for the same table, so exclude this possibility

2. It may be that you do not understand how to use JPA in Webflow, so try something:

-View the spring in action, the spring Web Flow authoritative guide, no instructions for using persistence in Web flow

-View the Webflow of the spring website, for the description of flow Managed persistence, mainly implement data persistence and transaction in one stream operation. Each time you enter a flow, a new persistence context is enabled, and a client connection is added to the MySQL background, which should wait until the flow is commit before it is released.

Here are 2 questions:

* Why does each flow enter a new database connection, and in theory Hibernate's session management mechanism creates a new session?

* If this flow is not fully executed, that is, it exits in the middle, then this persistence context can only wait until the connection timeout to release, if high concurrency that will soon hang, how to handle?

3. Verification

The connection pool to the maximum number of connections to 5, by clicking on the page, to the 6th page will be suspended no response, because you can not connect to 10s after the super-times wrong, at this time if the connection pool settings do not add maxwaitmillis= "10000" then will be waiting, this phenomenon will be unable to start investigation, We must pay attention to this point

<context><resource name= "jdbc/pt" type= "Javax.sql.DataSource" auth= "Container" maxtotal= "5" maxidle= "30" Maxwaitmillis= "10000" driverclassname= "Com.mysql.jdbc.Driver" Username= "PT" password= "pt123" url= "jdbc:mysql:// 127.0.0.1:3306/pt "/></context>

4. Resolve

Try to remove Webflow <persistence-context/> tags, data consistency to service processing

After removal, the query from the background database on the page is normal, but when one record in the selected query results jumps to the next page (the selected record ID is the action that the request parameters passed to flow, The action calls the service layer and then calls the DAO layer to load the specific information of this record), error:

Org.hibernate.LazyInitializationException:could not Initiali

The DAO layer is the Jparepository class that inherits spring, calls the GetOne method when loading, and views the GetOne Javadoc,see Also:EntityManager.getReference (class, Object)

The object is lazy-loaded.

The data can be displayed normally after switching to the FindOne method of the Crudrepository class.

Problem Solving!

Spring Webflow + Jpa + Hibernate run-time non-responsive problem handling

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.