Hibernate: how to enable show sql

By , last updated August 24, 2019

To see the SQL that your application sends to the database during the execution, insert the following property in your XML property file:

<bean id="sessionFactory"
		class="my.class.MyEntitySessionFactory">
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
		<property name="dataSource" ref="dbDataSource" />
</bean>

This is preferably done in the text.xml as you test the application.

In production you can enable logging with log4j in log4j.properties:

log4j.logger.org.hibernate.SQL=DEBUG