-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate SQL parameters logging
PostPosted: Wed Dec 21, 2016 4:42 am 
Newbie

Joined: Wed Dec 21, 2016 4:22 am
Posts: 2
Hello. I cannot set hibernate to write SQL request parameters values to log.

I work on project and it uses hibernate 4.1.8. After some search I found two solutions other people use for that but I was not able to make them work:

- set logging property org.hibernate.type to ALL. Later about that.
- use P6Spy - third party SQL driver. I was not able even set SQL connection. It crashes on first request and its description looks outdated.

As I would like not to take third party software even for debug, it would be much better to get how to set org.hibernate.type property.

I tried to set it in log4j.properties file:

Code:
log4j.logger.org.hibernate.type=ALL


I tried to set it in log4j.xml

Code:
   <logger name="org.hibernate.type">
       <level value="trace"/>
   </logger>

I know log4j reads xml config for sure, as I get errors in log if I put some wrong tags in log4j.xml.

Unfortunately this not works. May be pom.xml file broken. All I was able to get - SQL commands written to console, but only with hibernate.cfg.xml

Code:
<property name="hibernate.show_sql">true</property>


Also I saw some info that this could be caused by absent dependencies. I put in pom.xml anything could solve but no luck:

Code:
<!--hibernate -->       
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.1.8.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>4.1.0.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.7</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.2.0.Final</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>     
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.8.Final</version>
        <scope>compile</scope>
        <type>jar</type>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- Hibernate Spatial for mysql.  This will include Hibernate Spatial Core and JTS -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-spatial</artifactId>
        <version>4.0.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- custom type mappings for java 8 time classes -->
    <!--hibernate -->       
    <dependency>
        <groupId>ca.gfisystems</groupId>
        <artifactId>hibernate-utils</artifactId>
        <version>1.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- c3p0 used for postgresql connection -->
    <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
    </dependency>
    <!-- hibernate c3p0 connection pooling -->       
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>4.1.8.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- logback -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.1.3</version>
    </dependency>


Please help. It could be that I just search i wrong place and get many search results, but they are outdated. Link to relevant manual would be nice too.

Thanks.


Top
 Profile  
 
 Post subject: Re: Hibernate SQL parameters logging
PostPosted: Mon Jan 09, 2017 5:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Check out the following article:

The best way to log JDBC statements

This GitHub repository contains an example of how you can set up both p6spy and datasource-proxy.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.