1
   <persistence-unit name="acmDB" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>acm20-ds</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.show_sql" value="false"/>
         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>         
      </properties>
   </persistence-unit>

Sometimes I set hibernate.show_sql to true

But then I have to restart the application server again. I am using Weblogic 10 and JRebel.

Is it possible to set hibernate.show_sql to true in code at the location I need it?

Shervin Asgari
  • 23,901
  • 30
  • 103
  • 143
A.W.
  • 2,858
  • 10
  • 57
  • 90
  • For future reference, see this answer about how to get the SQL from a specific query. It may be overkill for this particular question, but it's the best way I've found to capture sql and tie it back to individual HQL, Criteria, or method calls. http://stackoverflow.com/questions/554481/how-to-get-sql-from-hibernate-criteria-api-not-for-logging/555192#555192 – Brian Deterling Dec 08 '11 at 16:27

1 Answers1

2

You can configure Hibernate to perform logging via your existing logging facilities such as Log4j, see 3.5. Logging. In this case you can control log level of Hibernate logging categories in runtime with your logging facilities.

For example, in Log4j:

//Enable SQL logging
Logger.getLogger("org.hibernate.type").setLevel(Level.DEBUG);

//Disable SQL logging
Logger.getLogger("org.hibernate.type").setLevel(Level.OFF);
axtavt
  • 239,438
  • 41
  • 511
  • 482
  • @Shervin: Yes, but then changing it whould require application restart, what op wants to avoid. – axtavt Feb 01 '11 at 15:06
  • Is that only weblogic? Because in JBoss you don't need to restart the application. JBoss will pick up the changes after a while – Shervin Asgari Feb 01 '11 at 15:17
  • @Shervin what axtavt meant is that Guus wants to programmatically turn on/off the logging, based on the code which is about to be executed, so that he gets only relevant queries in the log. – jpkroehling Feb 01 '11 at 16:00
  • 1
    Hi, I tried that but don't see hibernate debug lines. I use `@Logger Log log` from Seam in my class. Maybe that is the reason ? If I get it working than I won't have to restart because I use JRebel that picks up the changes. – A.W. Feb 02 '11 at 08:45