Java Hibernate Logging: Before or after sql eexectuion

Viewed 22

We have in the logging something like

09:53:02 server-1 java[5447]: 2022-03-10 09:53:02.262  INFO 5447 --- [io-18081-exec-6] a.w.w.service.item.LibItemService        : logging start
09:53:07 server-1 java[5447]: 2022-03-10 09:53:07.477 DEBUG 5447 --- [io-18081-exec-6] org.hibernate.SQL                        : select nextval ('lib_id_seq')

Logging is done via

logging:
  level:
    org:
      hibernate:
        SQL: TRACE

We are now discussing if the information about the SQL statement is before it is executed or after. The difference is: Whom to blame for the lost 5.2 seconds? The database OR the code which is done before?

1 Answers

Baeldung mentions that the code is generated by

The Spring/Hibernate classes, which generate SQL statements and set the parameters

So I would say "Before".

Edit: However, by browsing the logs with a long query, I got this:

2022-08-02 11:45:24.970  WARN 53550 --- [nio-2061-exec-2] c.i.c.s.cases.list.CaseQueryService      : My log just before the query
2022-08-02 11:45:26.868 DEBUG 53550 --- [nio-2061-exec-2] org.hibernate.SQL                        : 

Notice the ~2s duration before logging the SQL. So, actually, I'd say "after"!

Related