I got this error from the production code:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server
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:
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.)
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.
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?