Hibernate-4显示生成的SQL代码 [英] Hibernate-4 show SQL code that is generated

查看:48
本文介绍了Hibernate-4显示生成的SQL代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse IDE中创建了一个Maven项目,并尝试编写简单的休眠程序.但是我看不到hibernate生成的最终查询,该查询还包含绑定参数.

I created a Maven project in my eclipse IDE and trying to write simple hibernate program. But I am not able to see the final query that is generated by hibernate which also includes the bind parameters.

我还关注了此处提到的帖子: Hibernate显示真实的SQL ,但是没有帮助.

I also followed the post mentioned here : Hibernate show real SQL , but it did not help.

我有以下配置:

在我的hibernate.cfg.xml文件中,我有:

    <property name="show_sql">true</property>
    <property name="format_sql">true</property>
    <property name="use_sql_comments">true</property>

我还放置了log4j.properties文件及其内容:

I also placed log4j.properties file with its contents:

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.logger.net.sf.hibernate.type=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.xmllog4j.properties都位于路径:

MyProject/src/main/java/log4j.properties

但是当我运行一个小程序时,仍然看不到休眠添加的绑定参数,我只是看到以下结果:

But still when I run a small program I am not able to see the bind parameters that are added by hibernate, I am just seeing below results:

Hibernate: 
    select
        this_.ID as ID1_0_0_,
        this_.NAME as NAME2_0_0_
    from
        MY_TABLE this_ 

我正在使用Hibernate-4.3

推荐答案

pom.xml中添加SLF4J依赖性已解决了我的问题:

Adding SLF4J dependency in pom.xml has fixed my issue:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.6</version>
    </dependency>

这篇关于Hibernate-4显示生成的SQL代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆