Hibernate 使用 Simple Logging Facade for Java (SLF4J) 去记录各个系统事件。SLF4J 可以基于你选择的捆绑将你的日志输出到一些日志框架。
为了设置日志记录,你需要slf4j-api.jar在你的classpath下。在使用log4j的情况下必须有slf4j-log4j12.jar.为了使用log4j必须在classpath
下创建一个log4j.properties文件。举例来说这个配置文件在 src/目录下。
建议你熟悉一下hibernate的日志消息。很多工作被投入到hibernate日志中以便使他更为详细。最有趣的日志分类有以下几种:
Category | Function |
---|---|
org.hibernate.SQL | Log all SQL DML statements as they are executed |
org.hibernate.type | Log all JDBC parameters |
org.hibernate.tool.hbm2ddl | Log all SQL DDL statements as they are executed |
org.hibernate.pretty | Log the state of all entities (max 20 entities) associated with the session at flush time |
org.hibernate.cache | Log all second-level cache activity |
org.hibernate.transaction | Log transaction related activity |
org.hibernate.jdbc | Log all JDBC resource acquisition |
org.hibernate.hql.internal.ast.AST | Log HQL and SQL ASTs during query parsing |
org.hibernate.secure | Log all JAAS authorization requests |
org.hibernate | Log everything. This is a lot of information but it is useful for troubleshooting |
在开发hibernate应用时,在debug 中 org.hibernate.SQL总是被使用的,或者选择性使用
hibernate.show_sql