Hibernate 显示真实的 SQL
如果我设置
<property name="show_sql">true</property>
在控制台的hibernate.cfg.xml配置文件中,我可以看到SQL.
in my hibernate.cfg.xml configuration file in the console I can see the SQL.
但它不是真正的 SQL...我可以看到将直接传递给数据库的 SQL 代码吗?
But it's not real SQL... Can I see the SQL code that will be passed directly to database?
例子:
我明白了
select this_.code from true.employee this_ where this_.code=?
我可以看看
select employee.code from employee where employee.code=12
真正的 SQL?
推荐答案
log4j.properties
log4j.logger.org.hibernate=INFO, hb
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
log4j.appender.hb=org.apache.log4j.ConsoleAppender
log4j.appender.hb.layout=org.apache.log4j.PatternLayout
log4j.appender.hb.layout.ConversionPattern=HibernateLog --> %d{HH:mm:ss} %-5p %c - %m%n
log4j.appender.hb.Threshold=TRACE
hibernate.cfg.xml
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
persistence.xml
一些框架使用persistence.xml
:
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>
相关文章