Skip to content

Instantly share code, notes, and snippets.

@rponte
Created December 16, 2011 15:04
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save rponte/1486381 to your computer and use it in GitHub Desktop.
Save rponte/1486381 to your computer and use it in GitHub Desktop.
some ways to show sql generated by hibernate
Setting the hibernate.show_sql to true tells hibernate to Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug.
So even if you set this property to false, make sure that you don't have the following category defined (or configured to use a console appender):
log4j.logger.org.hibernate.SQL=DEBUG
Also, make sure that you don't set the hibernate.show_sql programmatically to true when instancing your Configuration object. Hunt something like this:
Configuration cfg = new Configuration().configure().
.setProperty("hibernate.show_sql", "true");
Note that the setProperty(String propertyName, String value) takes as first parameter the full name of a configuration property i.e. hibernate.show_sql, not just show_sql.
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
log4j.logger.org.hibernate=INFO, hb
log4j.logger.org.hibernate.SQL=DEBUG ## is equivalent to hibernate.show_sql=true
log4j.logger.org.hibernate.type=TRACE ## allows you to see the binding parameters
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.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
@rponte
Copy link
Author

rponte commented Mar 7, 2012

You can show DDL generated by SchemaExport with this:
log4j.logger.org.hibernate.tool.hbm2ddl=debug

@rponte
Copy link
Author

rponte commented Dec 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment