Hibernate 4 log4j view query parameters

I have a glass pane 4 hosted web application built using hibernate (JPA) and JSF and I want to view the request parameters.
I could see these options a while ago, but I think that when I switched from hibernate 3.x to 4.x, the log feature disappeared.
So I have in my persistence.xml:

<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>

      

and in my log4j.properties:

log4j.logger.org.hibernate=DEBUG
log4j.logger.org.hibernate.jdbc=trace
log4j.logger.org.hibernate.type= trace

      

The thing is, I see requests, but instead of params, I see question marks.
I read something about hibernate4 using jboss logging and I added this:

-Dorg.jboss.logging.provider=log4j

      

to my jvm options in glass shawl but no luck so far. Any ideas?

+3


source to share


2 answers


Try to set your application to you datasource-proxy in front of your actual datasource .

The datasource proxy can easily intercept all log requests and parameters. I use this logging method in all examples of my online Hibernate tutorial and you can check the configuration on GitHub .



Query:{[
select
    product0_.id as id1_18_1_,
    product0_.code as code2_18_1_,
    product0_.company_id as company_6_18_1_,
    product0_.importer_id as importer7_18_1_,
    product0_.name as name3_18_1_,
    product0_.quantity as quantity4_18_1_,
    product0_.version as version5_18_1_,
    company1_.id as id1_6_0_,
    company1_.name as name2_6_0_
from Product product0_
inner join Company company1_ on product0_.company_id=company1_.id
where product0_.id=?][1]

      

In square brackets, you will find the PreparedStatament parameters. It works even when calling procedures and functions.

+2


source


Glassfish Control Panel -> Configs -> Server-config -> Logger Settings -> Log Levels -> Add Logger -> org.hibernate.type: FINEST

Glassfish logger settings



source: https://cumacakmak.wordpress.com/2015/01/18/glassfish-hibernate-binding-parameters-easy-way/

+1


source







All Articles