If a failed lock query is executed, and the exception is caught, the log still shows:
o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
This spams the logs, but the SqlExceptionHelper
also shows helpful messages, like constraint violations, which would be omitted if the log level were set to FATAL
in application.properties
like so
logging.level.org.hibernate.engine.jdbc.spi.SqlExceptionHelper=FATAL
Is there a way to show some, but not all messages, from the SqlExceptionHelper?
The query is defined as
@Query(nativeQuery = true, value = "select * from locks for update nowait") List<Object> lockTable();
As written, the exception is handled, but the SqlExceptionHelper
still writes to the log.
If you can submit your database work via an anonymous PL/SQL block (BEGIN... END;
) then you can control exception handling natively yourself. Simply bind an exception name to the error you want to handle and wrap the failing call in a handler:
DECLARE
resource_busy exception;
PRAGMA EXCEPTION_INIT(resource_busy,-00054);
BEGIN
-- do my thing that might fail;
EXCEPTION
WHEN resource_busy THEN
NULL; -- do nothing, or replace with some sort of status/messaging so you know it failed
END;
If you are issuing a query to get back data, how you get data back from a PL/SQL block varies based on whether you need 1 row or multiple rows, and what the capabilities of your client are (ref cursor, collection, simple out vars, etc..). But the above demonstrates the concept of eliminating noise from an exception you don't care to see.