Enable Hibernate logging

前端 未结 5 1558
一生所求
一生所求 2020-12-03 03:04

I\'m trying to create a log of hibernate statements. I perform my sql statements using JPA where Hibernate 2.0 is the persistence provider (my application server is JBoss AS

5条回答
  •  悲&欢浪女
    2020-12-03 03:33

    Spring Boot, v2.3.0.RELEASE

    Recommended (In application.properties):

    logging.level.org.hibernate.SQL=DEBUG //logs all SQL DML statements
    logging.level.org.hibernate.type=TRACE //logs all JDBC parameters 
    

    parameters

    Note:
    The above will not give you a pretty-print though.
    You can add it as a configuration:

    properties.put("hibernate.format_sql", "true");
    

    or as per below.

    Works but NOT recommended

    spring.jpa.show-sql=true
    spring.jpa.properties.hibernate.format_sql=true
    

    Reason: It's better to let the logging framework manage/optimize the output for you + it doesn't give you the prepared statement parameters.

    Cheers

提交回复
热议问题