Display Hibernate SQL To Console (Spring)

The simplest approach probably is to set following logger to DEBUG:

org.hibernate.SQL

If you use log4j, find / create a log4j.properties file on your classpath root and add

log4j.logger.org.hibernate.SQL=DEBUG

See here for more info about log4j properties: http://logging.apache.org/log4j/1.2/manual.html


show_sql not a property of org.apache.commons.dbcp.BasicDataSource . You have to define it in session factory configuration. like this

 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="data" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
            <prop key="hibernate.current_session_context_class">thread</prop>
            <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>
</bean>