87.7k views
3 votes
If you want to see the Hibernate generated SQL statements on console, what should we do?

1 Answer

3 votes

Final answer:

To see the Hibernate generated SQL statements on console, configure the logging level in the Hibernate configuration file. Enabling 'hibernate.show_sql' or setting the logging level of 'org.hibernate.SQL' to 'DEBUG' will print the SQL statements to the console.

Step-by-step explanation:

To see the Hibernate generated SQL statements on console, you can enable the logging feature by configuring the logging level in the Hibernate configuration file. One way to do this is by setting the 'hibernate.show_sql' property to 'true'. This will print the SQL statements to the console as they are executed.

Another option is to set the logging level of the 'org.hibernate.SQL' category to a lower level like 'DEBUG'. This will enable SQL statement logging for Hibernate, and you can see the generated statements in the console output.

Here is an example of how you can configure Hibernate to show SQL statements on the console:

<property name="hibernate.show_sql" value="true" />
<logger name="org.hibernate.SQL" level="DEBUG" />

User Maxpaj
by
8.2k points