Automatic translation

Archives

February 2009
L My Me J V S D
"January March "
A
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Contributors

Display of parameter values ​​in the log hibernate

Hello,

I was faced with a problem for some time to display the value of the parameters passed in queries hibernate. In the logs, I saw only question marks that have frankly no added value.

I stumbled today on this Jira Hibernate: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2835 . With it, I just solved my problem and this solution may be able to help some people.

To summarize, there is conflict between some versions of log4j and some versions of Hibernate and in this case the parameter org.hibernate.type no longer relevant. To solve the problem, just follow these four steps:

  • Replace the file log4j category org.hibernate.type by org.hibernate.type.workaround
  • HibernateContext.xml file, add to the description of the sessionFactory bean dependency on bean hibernate-type-logging-workaround:
 <bean id="SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" singleton="true" depends-on="hibernate-type-logging-workaround"> 
  • Add the bean hibernate-type-logging-file workaround HibernateContext.xml
 <bean id="hibernate-type-logging-workaround" class="com.test.logger.LogHibernateHelper" singleton="true" /> 
  • Write LogHibernateHelper class as follows:
 com.test.logger package;
 org.apache.commons.logging.Log import;
 org.apache.commons.logging.LogFactory import;

 public class {LogHibernateHelper

    public LogHibernateHelper () {

       Log workaroundLog LogFactory.getLog = ("org.hibernate.type.workaround");
       Log typeLog LogFactory.getLog = ("org.hibernate.type");

       if (instanceof workaroundLog org.apache.commons.logging.impl.Log4JLogger
          & & Instanceof typeLog org.apache.commons.logging.impl.Log4JLogger) {

          org.apache.log4j.Logger log4jWorkaroundLogger = (org.apache.log4j.Logger)
            ((Org.apache.commons.logging.impl.Log4JLogger) workaroundLog). GetLogger ();
          org.apache.log4j.Logger log4jTypeLogger = (org.apache.log4j.Logger)
            ((Org.apache.commons.logging.impl.Log4JLogger) typeLog). GetLogger ();
          log4jTypeLogger.setLevel (log4jWorkaroundLogger.getLevel ());
       }
    }
 } 
In this way we obtain log much more useful because not only parameter values ​​but the values ​​returned.

  • Anonymous

    Which version you are using Hibernate and which version of commons-logging please?

  • Yoann http://www.yoann-ciabaud.fr Ciabaud

    Very useful indeed, I test it!

  • Mikael Barbeaux

    Super, I wanted it a few months ago without succès.Je when I tested it some time, thank you Clement!

  • Maxence http://m-button.blogspot.com B

    Clement hello! It's been a lease :) Friendly solution. Personally, when I want to see what is sent to the database, I use a JDBC wrapper, as P6Spy . This is a layer that is grafted just above the JDBC driver and log anything that starts at the base. More practical and very easy to implement (even more than playing with Log4j! : D ) By cons, beware: it can fill the perfs and fill a hard drive in one glance if a lot of activity ... DB

  • http://www.yahoo.fr saabrine

    salutje am beginner with liferay and I have a problem that I c 'comes to change the theme exactly I want to change the logo and put my own logo if you can help me explain to me how clearly. thank you for your attention

  • Anonymous

    Thank you for this solution!

    It becomes easier to debug the code!

  • http://www.gocredit.fr/ reserve of Argentine

    even I am not a pro, I succeeded! thank you.