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

Hybris环境下如何查看对象保存与操作时执行的查询?查询日志启用方法咨询

Enabling SQL Query Logging in Hybris for Queries & Object Operations

Absolutely, you can totally enable query logging in Hybris to track the exact SQL statements generated for both database queries and object operations like saves, updates, or deletes. Here's a straightforward guide to get you set up:

1. Basic Configuration via local.properties

The easiest way to turn on SQL logging is by adding these properties to your Hybris local.properties file (located in hybris/config/):

  • hibernate.show_sql=true: Prints raw SQL statements to the console (but without parameter values)
  • hibernate.format_sql=true: Formats the SQL output to make it easier to read
  • hibernate.use_sql_comments=true: Adds helpful comments to the SQL, like which Hibernate operation (e.g., /* insert com.yourcompany.yourstore.model.YourModel */) generated the statement
  • log4j.logger.org.hibernate.SQL=DEBUG: Routes SQL statements to your Hybris log files (not just the console)
  • log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=TRACE: Critical for seeing parameter values — this replaces the ? placeholders in SQL with actual data being passed

2. Where to Find the Logs

After restarting your Hybris server, you’ll find the SQL logs in:

  • The console output (if running Hybris locally)
  • Hybris log files, typically in hybris/log/tomcat/localhost.log or hybris/log/<your-storefront>/<your-storefront>.log depending on your setup

3. Tracking Object CRUD Operations

When you perform operations like modelService.save(myModel), modelService.update(myModel), or modelService.remove(myModel), Hibernate generates corresponding INSERT, UPDATE, or DELETE statements. With the above configuration, these statements will be logged along with:

  • Formatted SQL for readability
  • Parameter values (thanks to the BasicBinder logger)
  • Comments linking the SQL to the specific model operation

4. Advanced: Log4j2 Configuration (Newer Hybris Versions)

If your Hybris instance uses Log4j2 (common in newer versions), you’ll need to update your log4j2.xml file instead of using the log4j.logger properties. Add these logger entries:

<Logger name="org.hibernate.SQL" level="debug" additivity="false">
    <AppenderRef ref="CONSOLE"/>
    <AppenderRef ref="FILE"/>
</Logger>
<Logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="trace" additivity="false">
    <AppenderRef ref="CONSOLE"/>
    <AppenderRef ref="FILE"/>
</Logger>

Important Note

Keep in mind that enabling TRACE level logging (for BasicBinder) can impact server performance, so only use this during debugging or development. Disable it in production environments to avoid unnecessary overhead.

Once you’ve set these up, you’ll see detailed SQL logs exactly like the ones in the article you mentioned — including all statements for queries, saves, updates, and deletes. If you hit any snags getting this configured, feel free to follow up!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 12:28:12