13

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!

2
  • I have added log4j.logger.org.hibernate.type=TRACE but still no luck. Commented Aug 16, 2011 at 17:04
  • By the way, I am using JPA (annotation) for mapping and I use a generic DAO to create my model's DAO (using spring to inject the model into the a class which extends HibernateDaoSupport) Commented Aug 16, 2011 at 17:07

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

4 Comments

The hibernate.show_sql property isn't governed by logging. It writes directly to stdout.
It did do that, but it has changed in the past. On my console I get: [8/16/11 15:20:52:058 CEST] 00000038 SystemOut O 15:20:52.056 DEBUG [WebContainer : 6] org.hibernate.jdbc.util.SQLStatementLogger.logStatement:111 - select obfuscate0_.OUR_ID as OUR1_77_, obfuscate0_.USR_ID as USR2_77_, obfuscate0_.OFFICE as LVE3_77_, obfuscate0_.IDG_ID as IDGT4_77_, obfuscate0_.USRID_L
it worked. and it ended up to me my mistake, entity not loaded properly
Adding logging.level.org.hibernate=TRACE in the application.properties file worked for me.
4

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

2 Comments

added a System.out.println on the class for debug purpose. so I think I am checking the right log. =(
it worked. and it ended up to me my mistake, entity not loaded properly
1

In my case, I managed to correct this by adding a argument on JBoss launch configuration:

  1. Double click on "Red Hat JBoss EAP xxx".
  2. Click in "Open launch ocnfiguration" (tab "General Information").
  3. Add -Dorg.jboss.as.logging.per-deployment=false on the end of "VM arguments" field.

Worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.