Home > Java > javaTutorial > How Can I Log Hibernate SQL Queries with Parameter Values?

How Can I Log Hibernate SQL Queries with Parameter Values?

Mary-Kate Olsen
Release: 2024-12-25 10:45:08
Original
581 people have browsed it

How Can I Log Hibernate SQL Queries with Parameter Values?

Query String Logging with Parameter Values in Hibernate

Problem:

Can Hibernate display generated SQL queries with actual parameter values instead of question marks? If not, how can these queries be printed with real values?

Solution:

Using Hibernate Logging:

  1. Enable logging for the following categories:

    • org.hibernate.SQL: Set to debug to log SQL DML statements as they execute.
    • org.hibernate.type: Set to trace to log JDBC parameters.
  2. Configure log4j as follows:
# Logs SQL statements
log4j.logger.org.hibernate.SQL=debug 

# Logs JDBC parameters
log4j.logger.org.hibernate.type=trace
Copy after login

Using P6Spy JDBC Proxy Driver:

As an alternative to Hibernate logging, the P6Spy JDBC proxy driver can be used. This driver intercepts JDBC calls and logs them with detailed information, including parameter values.

The above is the detailed content of How Can I Log Hibernate SQL Queries with Parameter Values?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template