java - Hibernate 查询日志记录 - 从实体名称记录
问题描述
我通过在我的 application.properties 中设置以下配置在 Hibernate 中使用查询日志记录
logging.level.org.springframework.transaction.interceptor=DEBUG
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=DEBUG
这很好用并记录查询。我需要通过在开头添加一个表名来增强此日志记录,我从哪个表中选择数据。例如,我记录了以下查询:
2021-06-16 13:11:18.008 DEBUG 6544 --- [io-8080-exec-10] org.hibernate.SQL : select count(program0_.id) as col_0_0_ from public.program program0_ where 1=1
2021-06-16 13:11:18.008 DEBUG 6544 --- [io-8080-exec-10] org.hibernate.SQL : select count(user_0 .id) as col_0_0_ from public.user user_0 where 1=1
这些查询很简单,很容易确定是从表program
和user
. 但是在大查询的情况下,开头的表名会简化日志的检查。
是否有任何选项如何在 Hibernate 中进行设置?
解决方案
Hibernate 没有这样的选项。
评论已经描述了需求定义不明确,因为您可以在任何 SQL 语句中拥有任意数量的表,包括 0,因此通用解决方案相当棘手。
但是你可以自己做这样的事情。
例如,如果您使用 Logback,您可能会注册一个解析消息的自定义布局,如果它找到 SQL 语句,它会从中提取表。
或者,您可以使用您用来收集和整合日志的工具链对日志进行后处理
推荐阅读
- javascript - 有谁知道如何使起始编号和结束编号产生一个无序列的平方根列表?
- asp.net-core - DevOps Nu1607 NU1607:检测到版本冲突如果我没有指定 AspNetCore 版本
- java - 无法使用标签从命令行执行 maven 测试?
- python - 我是否在 Python 3 中正确/错误地使用编码将字符串转换为字节?
- codenameone - 使用 MapContainer 的 OutOfMemoryError
- python-3.x - 如何用唯一的文件名python重命名文件
- javascript - 如何验证变量实际上是一个 joi 模式?
- javascript - 大型语料库上的客户端文本搜索
- python - socket.io 仅在页面刷新时发出
- firebase - Firestore 引用创建“TypeError:将循环结构转换为 JSON”