日志中输出 Hibernate HQL 中的参数

2022-02-19 10:31:41 浏览数 (3)

发表于2018-05-262019-01-01 作者 wind

需要设置 hibernate 的日志的实现,我这里用slf4j:

代码语言:javascript复制
public static void main(String[] args) {
    System.setProperty("jboss.logging.provider", "slf4j");
    SpringApplicationBuilder builder = new SpringApplicationBuilder().web(true).sources(Application.class).profiles(
        "web");
    builder.run(args);
}

我用的是spring boot项目结构,所以在application.yml里面直接配置日志:

代码语言:javascript复制
logging:
  level:
    root: info
    org.hibernate.hql.internal.ast.HqlSqlWalker: error
    org.hibernate.type.descriptor.sql.BasicBinder: trace
#    org.hibernate.type.descriptor.sql.BasicExtractor: trace
    org.hibernate.engine.spi.QueryParameters: trace
#    org.hibernate.engine.query.spi.HQLQueryPlan: trace
    cn.firegod: debug

这样在执行的时候,就会有类似下面这样的输出:

代码语言:javascript复制
Hibernate: select courseenti0_.id as id1_15_0_, courseenti0_.create_by as create_b2_15_0_, courseenti0_.create_date as create_d3_15_0_, courseenti0_.del_flag as del_flag4_15_0_, courseenti0_.name as name5_15_0_, courseenti0_.remarks as remarks6_15_0_, courseenti0_.update_by as update_b7_15_0_, courseenti0_.update_date as update_d8_15_0_ from cdev_school_course courseenti0_ where courseenti0_.id=?
2018-05-26 13:40:40.523 TRACE 64785 --- [nio-9999-exec-2] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [INTEGER] - [1]

0 人点赞