Enabling Hibernate logging SQL + Query Parameters
in TR Internal
How do I enable logging for Hibernate's SQL + the JDBC query parameters used in that SQL?
I am already able to successfully get the SQL to display, it just doesn't have the query parameters included. E.g.:
Hibernate:
select
container0_.CONTAINER_VERSION_ID as CONTAINER1_0_,
container0_.CONTAINER_ID as CONTAINER2_0_,
container0_.LAST_MODIFIED_DATE as LAST3_0_,
container0_.STATE as STATE0_,
container0_.TYPE as TYPE0_
from
CONTAINERS container0_
where
container0_.CONTAINER_ID=?
and container0_.STATE=?
Getting the SQL to display was done via the database spring context XML file:
org.hibernate.dialect.Oracle10gDialect
thread
org.hibernate.cache.NoCacheProvider
false
${hibernate.show.sql}
${hibernate.format.sql}
5
true
true 1, false 0
And then setting the hibernate.show.sql and hibernate.format.sql properties to true in my local .properties file:
hibernate.show.sql=true
hibernate.format.sql=true
To get the JDBC parameters to log, this StackOverflow thread indicates that I should be able to set:
log4j.logger.org.hibernate.type=trace
or
log4j.logger.org.hibernate.SQL=trace
for Hibernate 3.2.x
I've tried doing this in both my local .properties file (localdevelopment_webContent.properties file in my case), and additionally by updating my local logging config XML file
But nothing seems to work. I know there aren't too many others working on the WebContent module, but is there anyone in another module that uses Hibernate that has successfully gotten these parameters logging with Cobalt? Perhaps foldering?
I am already able to successfully get the SQL to display, it just doesn't have the query parameters included. E.g.:
Hibernate:
select
container0_.CONTAINER_VERSION_ID as CONTAINER1_0_,
container0_.CONTAINER_ID as CONTAINER2_0_,
container0_.LAST_MODIFIED_DATE as LAST3_0_,
container0_.STATE as STATE0_,
container0_.TYPE as TYPE0_
from
CONTAINERS container0_
where
container0_.CONTAINER_ID=?
and container0_.STATE=?
Getting the SQL to display was done via the database spring context XML file:
org.hibernate.dialect.Oracle10gDialect
thread
org.hibernate.cache.NoCacheProvider
false
${hibernate.show.sql}
${hibernate.format.sql}
5
true
true 1, false 0
And then setting the hibernate.show.sql and hibernate.format.sql properties to true in my local .properties file:
hibernate.show.sql=true
hibernate.format.sql=true
To get the JDBC parameters to log, this StackOverflow thread indicates that I should be able to set:
log4j.logger.org.hibernate.type=trace
or
log4j.logger.org.hibernate.SQL=trace
for Hibernate 3.2.x
I've tried doing this in both my local .properties file (localdevelopment_webContent.properties file in my case), and additionally by updating my local logging config XML file
But nothing seems to work. I know there aren't too many others working on the WebContent module, but is there anyone in another module that uses Hibernate that has successfully gotten these parameters logging with Cobalt? Perhaps foldering?
Tagged:
1
Best Answer
-
I've also wanted access to the prepared statement parameters being used by hibernate a few years back, but never found a solution. I did hear that using a proxy JDBC driver is a work around to get this information. The proxy JDBC driver intercepts and logs all SQL traffic before forwarding the SQL on to the database. I've never taken the time to play around with it myself. Here's a list of proxy JDBC drivers. I believe P6Spy was the industry leader when I heard about it a few years back.
http://www.manageability.org/blog/stuff/jdbc-proxy-drivers3
Answers
-
Might be a sledgehammer for your problem, but you could try out Hibernate Profiler (
http://hibernateprofiler.com/), which would allow you to see and debug the SQL statements being issued by Hibernate.2 -
I wasn't able to find a simpler solution and didn't actually use this one, but from other searches on the internet, this seems to be correct.0
-
Can you post your entire logging properties file? I've been able to log SQL and param values before using the log settings you have, so I suspect there's some other problem.1
-
I don't know that these are 100% the same as when I asked this question, but here they are:
Logging config:
$/Cobalt WebContent/Development/LoggingConfig/WebContentLogging.xml0 -
Relevant Spring config:
$/Cobalt WebContent/Development/WebContent/config/WebContent-database-context.xml0 -
Local logging config:
$/Cobalt WebContent/Development/WebContent/resources/localdevelopment_WebContent-logging.xml0 -
Local .properties file:
$/Cobalt WebContent/Development/WebContent/resources/localdevelopment_webContent.properties0 -
I don't know if this topic is still active, but I have the following in my log4j.xml - supports displaying formatted sql and binding parameters:1
-
Cool. Thanks Robert.0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛