Home > Database > Mysql Tutorial > How Can I See the Exact SQL Executed by Hibernate?

How Can I See the Exact SQL Executed by Hibernate?

Barbara Streisand
Release: 2025-01-21 07:51:10
Original
270 people have browsed it

How Can I See the Exact SQL Executed by Hibernate?

Unlocking Hibernate's True SQL: A Deep Dive into Logging and Proxies

While setting hibernate.show_sql=true displays SQL queries in your logs, these aren't always the exact statements sent to your database. This article explains how to see the precise SQL.

Revealing the Exact SQL:

To view the actual SQL code executed against your database, utilize one of these methods:

  • JDBC Driver Proxies: Employ tools like P6Spy or log4jdbc. These act as intermediaries between your application and the JDBC driver, intercepting and displaying the actual SQL statements.

  • Enhanced Logging: Configure your logging to include these categories:

<code>log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE</code>
Copy after login

The first setting mirrors hibernate.show_sql=true, but the second provides crucial details about the bound parameters, completing the picture.

Further Reading:

The above is the detailed content of How Can I See the Exact SQL Executed by Hibernate?. For more information, please follow other related articles on the PHP Chinese website!

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