0

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.

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

I have below configurations:

In my hibernate.cfg.xml file I have:

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

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

Both hibernate.cfg.xml and log4j.properties are placed at path :

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_ 

I am using Hibernate-4.3

3 Answers 3

1

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>
0

Change this line:

log4j.logger.net.sf.hibernate.type=debug

to:

log4j.logger.org.hibernate.type=trace

And you should get the bind parameter.

3
  • @user2065083 I have changed my answer. please try again.
    – Jens
    Aug 27, 2014 at 7:01
  • I already have that setting in my log4j.properties file --> log4j.logger.org.hibernate.type=TRACE, now I tried removing only the line log4j.logger.net.sf.hibernate.type=debug, still no change in output
    – Chaitanya
    Aug 27, 2014 at 7:13
  • Thanks Jens for your support, I don't have slf4j in my pom.xml dependency list so the log4j.properties file is not picked.
    – Chaitanya
    Aug 27, 2014 at 7:26
0

The log4j.properties file must be located in the following directory:

MyProject/src/main/resources/log4j.properties

Thus, log4j will find this file in the classpath without any additional configuration.


See also Introduction to the Standard Directory Layout in the Apache Maven webpage.

You may want to see the next question: Logging server logs to one file and SQL logs to another.

1
  • Thanks Paul for the answer, I have placed it in resources path, but still there is no change in the output, this way is not working for me.
    – Chaitanya
    Aug 27, 2014 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.