Hibernate: how to enable show sql

By , last updated May 17, 2017

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

Comments

Be the first to comment.

Leave a Reply


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*