Last Updated: February 25, 2016
·
920
· corleonis

Enable SQL printing in Hibernate

To enable SQL output for Hibernate you have two steps:

1. show_sql

Enable the logging of all the generated SQL statements to the console

<!--hibernate.cfg.xml -->
<property name="show_sql">true</property>

2. format_sql

Format the generated SQL statement to make it more readable, but takes up more screen space. :)

<!--hibernate.cfg.xml -->
<property name="format_sql">true</property>

And last optional but nice to have step:

3. usesqlcomments

Hibernate will put comments inside all generated SQL statements to hint what’s the generated SQL trying to do

<!--hibernate.cfg.xml -->
<property name="use_sql_comments">true</property>