Show Hibernate SQL queries with values in Spring Boot

featured_image

When debugging a hibernate related issue, it is useful to examine queries in the console. Check out how to print them with binding parameters.

To log queries with values as console output, add the following lines to the application-development.properties file:

Check out the example output given after calling a simple action for creating a new user account:

For security and performance reasons print queries only when you need to debug them and avoid doing this on the production environment.

Properties explained

Show only queries

This property allows us to see only the prepared statement:

Format output

To beautify the output and make it more readable we can add the format property:

Now the same query is displayed in a more comprehensible way:

Include binding parameters

To print values we need the following line:

Finally, the output contains also the binding parameters values:

Photo by frank mckenna on StockSnap

Leave a Reply

Your email address will not be published. Required fields are marked *