Reproduce com.mysql.jdbc.exceptions.jdbc4.CommunicationsException with a setup of Spring, hibernate and C3P0

后端 未结 3 971
独厮守ぢ
独厮守ぢ 2020-12-31 07:31

I got this error from the production code:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server

3条回答
  •  醉话见心
    2020-12-31 07:55

    Fei - could be one of several things, can't really say based on the info posted so far.

    Suggest you add MySQL/Spring/Hibernate/C3PO/JDBC version numbers to your question, in case there is a known issue out there.

    The production error message is a common one, with many possible root causes. Some leads for you:

    1. The production error may indicate that your application is not releasing a connection back to the pool when done with it, preventing c3p0 from checking it. (The c3p0 idle checks can only be applied to unchecked-out connections.)

    2. Check that c3p0 is really working (you may be using 'vanilla' connections if not). In your test, if you set (e.g.) MySql wait_timeout=10, application thread sleep=35, and idleConnectionTestPeriod=30, if pooling is working, the exception should go away.

    3. On the expense of the idle checks: consider not using the default getTables() - maybe set preferredTestQuery to something cheap(-er) 'SELECT 1' maybe for MySQL?

提交回复
热议问题