当我收到以下异常时
19:36:35,712 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - SQL Error: 1205, SQLState: 40001
19:36:35,713 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Lock wait timeout exceeded; try restarting transaction
org.springframework.dao.PessimisticLockingFailureException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.PessimisticLockException: could not execute statement
该特定连接处于不良状态,然后在10分钟后出现以下错误
19:48:41,859 WARN [com.mchange.v2.c3p0.impl.NewPooledConnection] - [c3p0] A PooledConnection that has already signalled a Connection error is still in use!
19:48:41,859 WARN [com.mchange.v2.c3p0.impl.NewPooledConnection] - [c3p0] Another error has occurred [ java.sql.SQLNonTransientConnectionException: No operations allowed after connection closed. ] which will not be reported to listeners!
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: The last packet successfully received from the server was 716,308 milliseconds ago. The last packet sent successfully to the server was 716,308 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem
通常在发生异常时,事务回滚和连接可用于将来的请求。
如何通过锁定等待超时实现相同的目的?
我使用Java Spring Hibernate MySQL和C3P0
这里是配置
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
hibernate.hbm2ddl.delimiter=;
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=250
hibernate.c3p0.checkout_timeout=120000
hibernate.c3p0.test_connection_on_checkin=true
hibernate.c3p0.idle_connection_test_period=300
hibernate.archive.autodetection=class
hibernate.hbm2ddl.auto=validate
这是因为实时会话管理不善,或者甚至无法执行所有查询的选项,或者是由于事务隔离级别选择不当