Hibernate show real SQL
To show the real SQL generated by Hibernate, you can enable the show_sql
property in the Hibernate configuration file (hibernate.cfg.xml
). This will cause Hibernate to log all the SQL statements it generates to the console or to a log file.
Here is an example of how you can enable the show_sql
property in the Hibernate configuration file:
<property name="show_sql">true</property>
Alternatively, you can enable the show_sql
property programmatically using the setProperty()
method of the Configuration
class.
Here is an example of how you can enable the show_sql
property programmatically:
Configuration config = new Configuration();
config.setProperty("hibernate.show_sql", "true");
Keep in mind that enabling the show_sql
property can have a negative impact on the performance of your application, as it causes Hibernate to log all the SQL statements it generates. You should only enable the show_sql
property for debugging purposes and disable it in production.
You can also use the getSQL()
method of the SQLQuery
class to get the real SQL generated by Hibernate for a specific query.
For example:
String sql = ((SQLQuery) session.createQuery("from Employee")).getSQL();
This will return the real SQL generated by Hibernate for the Employee
class.
I hope this helps! Let me know if you have any other questions.