Why can't I catch org.hibernate.PessismisticLockException?

Hi,
I found the following errors in my server log.

2022-02-24 17:09:54 [pool-2297-thread-1] WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 1205, SQLState: 40001                                                                                         
2022-02-24 17:09:54 [pool-2297-thread-1] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Lock wait timeout exceeded; try restarting transaction                                                                   
2022-02-24 17:09:54 [pool-2297-thread-1] INFO  o.h.e.i.DefaultLoadEventListener - HHH000327: Error performing load command                                                                                  
org.hibernate.PessimisticLockException: could not extract ResultSet                                                                                                                                         
        at org.hibernate.dialect.MySQLDialect$3.convert(MySQLDialect.java:542)                                                                                                                              
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)                                                                                    
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)                                                                                                            
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)                                                                                                             
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)                                                                                                      
        at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet(AbstractLoadPlanBasedLoader.java:390)                                                                           
        at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:163)                                                                  
        at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:104)                                                                            
        at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:285)                                                                              
        at org.hibernate.persister.entity.AbstractEntityPersister.doLoad(AbstractEntityPersister.java:4437)                                                                                                 
        at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4427)                                                                                                   
        at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:576)                                                                                      
        at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:544)                                                                                                  
        at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:208)                                                                                                    
        at org.hibernate.event.internal.DefaultLoadEventListener.lockAndLoad(DefaultLoadEventListener.java:477)                                                                                             
        at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:111)                                                                                                
        at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:74)                                                                                                   
        at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:110)                                                                             
        at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1186)                                                                                                                       
        at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1175)                                                                                                                               
        at org.hibernate.internal.SessionImpl.access$2100(SessionImpl.java:193)                                                                                                                             
        at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2779)                                                                                                        
        at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1(SessionImpl.java:2767)                                                                                                 
        at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2723)                                                                                                       
        at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2767)                                                                                                          
        at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3322)                                                                                                                                   
        at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3294)                                                                                                                                   
        at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)                                                                                                                                     
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                            
        at java.lang.reflect.Method.invoke(Method.java:498)                                                                                                                                                 
        at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:310)                                                          
        at com.sun.proxy.$Proxy74.find(Unknown Source)                                                                                                                                                      
        at org.example.tpcc.server.dao.WarehouseDao.getWarehouseById(WarehouseDao.java:20)                                                                                                                    
        at org.example.tpcc.server.dao.WarehouseDao$$FastClassBySpringCGLIB$$4c2896f3.invoke(<generated>)                                                                                                     
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)                                                                                                                         
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)                                                                                    
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)                                                                                        
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)                                                                                            
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)                                                           
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)                                                                                        
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)                                                           
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)                                                                                        
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)                                                                                            
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)                                                                                      
        at org.example.tpcc.server.dao.WarehouseDao$$EnhancerBySpringCGLIB$$ef110e88.getWarehouseById(<generated>)                                                                                            
        at org.example.tpcc.server.service.PaymentService.Payment(PaymentService.java:32)                                                                                                                     
        at org.example.tpcc.server.service.PaymentService$$FastClassBySpringCGLIB$$5b8d0070.invoke(<generated>)                                                                                               
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)                                                                                                                         
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)                                                                                    
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)                                                                                        
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)                                                                                            
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)                                                                      
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)                                                                  
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)                                                                                       
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)                                                                                        
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)                                                                                            
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)                                                                                      
        at org.example.tpcc.server.service.PaymentService$$EnhancerBySpringCGLIB$$c1c3f106.Payment(<generated>)                                                                                               
        at org.example.tpcc.server.controller.PaymentController.lambda$payment$0(PaymentController.java:32)                                                                                                   
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction                                                                           
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:123)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)                                                                                              
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
        ... 56 common frames omitted

I know it is caused by acquiring lock timeout in a database transaction, but I don’t care and I just hope that transaction can rollback quietly without making server log dirty.
Therefore I try to catch PessmisticLockException in WarehouseDao, PaymentServeice or PaymenController and do nothing to ignore it. However, my works failed and the error log still exists.
Is there anyone know why this happened,and how to solve it?

I don’t know why you would want to disable such log messages, but you can disable the logger org.hibernate.event.internal.DefaultLoadEventListener and org.hibernate.engine.jdbc.spi.SqlExceptionHelper in your logging configuration to avoid seeing this message.