I am not sure why it doesn't show sql statement. I have it working before (on older spring, I am using 3 this time)
In ApplicationContext I have :
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>my.model.*</value>
</list>
</property>
</bean>
In log4j:
# Standrd System.out appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.Threshold=DEBUG
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# package override setting
log4j.logger.org.hibernate.SQL=DEBUG, stdout
log4j.additivity.org.hibernate.SQL=false
log4j.logger.org.displaytag=INFO
log4j.rootLogger=DEBUG, stdout
Everything else seems fine, but it just doesn't show me the sql.
Did I miss anything?
(Or is it possible to print from SessionFactory from org.hibernate.cfg.Environment.getProperties()? It is not showing the show_sql, probably not even injected properly?)
Please help Thanks in advance!
show_sql to true tells hibernate to Write all SQL statements to console. This is an alternative to setting the log category org. hibernate. SQL to debug.
For Hibernate Native SQL Query, we use Session. createSQLQuery(String query) to create the SQLQuery object and execute it. For example, if you want to read all the records from Employee table, we can do it through below code. When we execute above code for the data setup we have, it produces following output.
make sure DEBUG is good, at one point hibernate logging changed from DEBUG to TRACE.
Also make sure there is no threshold in your log4j.config
.
if you want also your arguments to be displayed include org.hibernate.type
. You may also need to set org.hibernate.jdbc=TRACE
or try org.hibernate=TRACE
analyse your needs and change back to proper levels per package.
You have hibernate.show_sql configured correctly. Where are you looking for the output? In any case, it's better to just forget about show_sql and use Hibernate's logging instead. It's much more flexible. Remove the "hibernate.show_sql" property entirely, and in your logging config use
log4j.logger.org.hibernate.SQL=TRACE
log4j.logger.org.hibernate.type=TRACE
Note that there's no reason to mess with the additivity since everything is writing to the same appender, so this line doesn't do anything and should be removed:
log4j.additivity.org.hibernate.SQL=false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With