skip to Main Content

On my MySQL server, in the general log I see a ton of logs that look like:

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

I would like to see them on the clientside logs, however. My Java is very rusty so please be patient. In case it’s helpful, the question I’m asking looks very similar to this one, though the accepted answer there didn’t actually end up working out for me either (this is a separate issue) :/

I have a YAML file and have tried enabling the following:

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

2

Answers


  1. Hibernate does not send those queries. It is the JDBC driver which sends them. The relevant JDBC API is java.sql.Connection.setAutoCommit(), and in a container environment that method is usually called by your connection pool.

    Login or Signup to reply.
  2. Hibernate config like is like this to enable auto commit:

    <property name="connection.autocommit">true</property>

    Transaction Level can be set in the code

    EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("sampleUnit");
    EntityManager em1 = emFactory.createEntityManager();
    EntityTransaction t1 = em1.getTransaction();
    t1.begin();
    try {
      Query query = em1.createQuery("SELECT p FROM Product p WHERE name = :name");
      query.setParameter("name", "cherry");
      List<Product> products = query.getResultList();
      System.out.println("Got product size: "+products.size());
    } finally {
      t1.rollback();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search