开发者

Hibernate not showing sql statement even with sql_show=true

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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜