views:

158

answers:

2

I have the following code and I am still unable to get Hibernate to write SQL queries to log file. It perfectly writes them to the Eclipse console.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="file" 
 class="org.apache.log4j.RollingFileAppender">
 <param name="maxFileSize" value="500KB"/>
 <param name="maxBackupIndex" value="5"/>
 <param name="File" value="hibernate.log"/>
 <layout class="org.apache.log4j.PatternLayout">
  <param name="ConversionPattern"
    value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
 </layout>
</appender>

<logger name="org.hibernate.SQL">
    <level value="info"/>
    <appender-ref ref="file"/>
</logger>


<root>
<priority value="info"></priority>
<!--  -->
</root>


</log4j:configuration>

Can somebody explain why? I have feeling that element and it's element has to do something with that but have no clue what this element does? Can someone post a link or something where I can read this.

+2  A: 

org.hibernate.SQL only logs the SQL at debug level- you need something like this:

<logger name="org.hibernate.SQL">
  <level value="debug" />
  <appender-ref ref="file" />
</logger>
araqnid
+1  A: 

Configure log4j as follow:

<logger name="org.hibernate">
    <level value="debug"/>
    <appender-ref ref="file"/>
</logger>

after that you have to configure "hibernate.show_sql" hibernate property to true