How to view the SQL queries issued by Hibernate to set transaction level and autocommit
P粉734486718
P粉734486718 2023-09-13 10:04:00
0
1
580

On my MySQL server, in the general logs I see a lot of logs like this:

2023-03-31T09:31:23.208-07:00   2023-03-31T16:31:23.208345Z37028 Query SET autocommit=0
2023-03-31T09:31:23.211-07:00   2023-03-31T16:31:23.211201Z36956 Query set session transaction read write
2023-03-31T09:31:23.211-07:00   2023-03-31T16:31:23.211807Z36957 Query /* dynamic native SQL query */ select now() /*app health check*/
2023-03-31T09:31:23.255-07:00   2023-03-31T16:31:23.255990Z36995 Query set session transaction read write
2023-03-31T09:31:23.273-07:00   2023-03-31T16:31:23.273013Z36957 Query set session transaction read write
2023-03-31T09:31:23.276-07:00   2023-03-31T16:31:23.276323Z36956 Query SET autocommit=0
2023-03-31T09:31:23.320-07:00   2023-03-31T16:31:23.320214Z36995 Query SET autocommit=0
2023-03-31T09:31:23.334-07:00   2023-03-31T16:31:23.334801Z36957 Query SET autocommit=0
2023-03-31T09:31:23.461-07:00   2023-03-31T16:31:23.461897Z37056 Query rollback

However, I would like to see them in the client log. I'm very rusty with Java, so please bear with me. If it helps, the question I'm asking looks very similar to this one, although the accepted answer there didn't actually solve it for me either (that's a separate question) :/

I have a YAML file and try to enable the following features:

logging:
  levels:
  - path: org.hibernate
    value: trace
  - path: org.hibernate.SQL
    value: debug
  - path: org.jooq
    value: trace
  - path: com.amazonaws
    value: debug
  - path: com.zaxxer
    value: debug
  - path: com.mysql
    value: debug
  - path: org.hibernate.engine.transaction.internal.TransactionImpl
    value: debug
  - path: com.mysql.clusterj.core.TransactionImpl
    value: debug
  - path: org.hibernate.jpa.internal.TransactionImpl
    value: debug

P粉734486718
P粉734486718

reply all(1)
P粉155128211

Hibernate will not send these queries. It is the JDBC driver that sends them. The relevant JDBC API is java.sql.Connection.setAutoCommit(), which in a container environment is typically called by a connection pool.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template