1

While struggling to see Hibernate-generated SQL queries in JBoss7 log, I'm looking for a definitive answer to following question:

Q: Should entries in both of these config locations be present AT THE SAME TIME, or does any one override another?

1) in log4j.properties

log4j.logger.org.hibernate.SQL=ALL #or DEBUG

2) in persistence.xml

<persistence-unit...>
   <properties>
      <property name="hibernate.show_sql" value="true"/>
      ...

This is a vital question for me as I can only edit 1).

1 Answer 1

2

The requirement for logging are these (ofc you have to specify a file appender):

1) on log4j2.xml

//if you put this to trace, you'll log the variables putted into the queries
<logger name="org.hibernate.type" level='trace' additivity="false" >
    <appender-ref ref='FileLog'></appender-ref>
</logger>

2) on log4j2.xml

//with debug, you will log the query itself
<logger name='org.hibernate.SQL' level='debug' additivity='false'>
  <appender-ref ref='FileLog'></appender-ref>
</logger>

3) on hibernate.cfg.xml

<property name="hibernate.show_sql">true</property>

EDIT: this is an example of appender

<appenders>
   <File name="FileLog" fileName="c:/path/your.log"></File>
</appenders>
1
  • OK, so I understand from this that they work in conjunction (not override one another). That is: I have to set BOTH (which I am unable to do, but good to know this is how it works). Jul 17, 2018 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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