hibernate Enable/Disable SQL log in debug


Example

Some applications that use Hibernate generate a huge amount of SQL when the application is started. Sometimes it's better to enable/disable the SQL log in specific points when debugging.

To enable, just run this code in your IDE when you are debugging the aplication:

org.apache.log4j.Logger.getLogger("org.hibernate.SQL")
    .setLevel(org.apache.log4j.Level.DEBUG)

To disable:

org.apache.log4j.Logger.getLogger("org.hibernate.SQL")
    .setLevel(org.apache.log4j.Level.OFF)