Display Hibernate SQL To Console (Spring) Display Hibernate SQL To Console (Spring) sql sql

Display Hibernate SQL To Console (Spring)


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>


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


As I'm using JEE 8 and JBoss EAP, I managed to got the SQL after adding this line:

-Dorg.jboss.as.logging.per-deployment=false

on the end of "VM arguments" (Server tab -> JBoss Properties -> Open lauch configuration).