You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在JHipster中启用Hibernate统计功能?

Troubleshooting Hibernate Logging in JHipster 5.7.2 + Spring Boot 2.0.7

Hey there! I get how frustrating it is when you’ve tried multiple configs to get Hibernate’s SQL and parameter logging working, and nothing sticks—especially when you’re new to JHipster and Spring Boot. Let’s break down why your current setups might not be working, and fix it step by step.

First, keep in mind that JHipster has its own opinionated logging structure, so your configs might be getting overridden or not loaded correctly depending on where you place them. Here’s what you need to do:

1. Fix Your Logback Configuration

JHipster typically uses a src/main/resources/config/logback-spring.xml file with profile-specific blocks. Make sure you’re adding your Hibernate logger configs inside the dev springProfile block—otherwise, they won’t apply when running in development mode.

Here’s the corrected snippet to add:

<springProfile name="dev">
    <!-- Keep your existing dev log configs here -->
    <!-- Enable Hibernate SQL statement logging -->
    <logger name="org.hibernate.SQL" level="DEBUG"/>
    <!-- Enable parameter binding details (replaces the old org.hibernate.type in newer Hibernate versions) -->
    <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE"/>
    <!-- Optional: Enable Hibernate stats if needed -->
    <logger name="org.hibernate.stat" level="DEBUG"/>
</springProfile>

Note: The org.hibernate.type logger is deprecated in newer Hibernate versions (included with Spring Boot 2.0.x), so using BasicBinder will show you the actual parameter values being bound to SQL queries.

2. Correct Your application-dev.yaml Format

YAML is super picky about indentation—if your configs aren’t properly indented, Spring won’t parse them correctly. Here’s the properly formatted version:

logging:
  level:
    org.hibernate.SQL: DEBUG
    org.hibernate.type.descriptor.sql.BasicBinder: TRACE
    org.hibernate.stat: DEBUG

Double-check that each level under logging.level is indented with 2 spaces (don’t use tabs!)—this is a common gotcha that breaks YAML parsing.

3. Verify Dev Profile is Active

Make sure your app is actually running with the dev profile activated. You can confirm this by checking your startup logs—you should see a line like:

The following profiles are active: dev

If not, start your app with the dev profile explicitly:

  • Using Maven: ./mvnw spring-boot:run -Dspring.profiles.active=dev
  • Using Gradle: ./gradlew bootRun --args='--spring.profiles.active=dev'
  • In IDEs like IntelliJ/Eclipse: Add --spring.profiles.active=dev to your run configuration’s program arguments.

4. Check for Overridden Log Levels

JHipster might have default log level settings that override your configs. Look for any root logger config in logback-spring.xml that’s set to a level higher than DEBUG (like INFO). If it is, make sure your Hibernate loggers are explicitly set to DEBUG/TRACE to override the root level.

Once you’ve made these changes, restart your app and check the logs—you should now see full SQL queries and the parameter values being bound to them.

内容的提问来源于stack exchange,提问作者sweetacaro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:18:18