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

How Can I See the Exact SQL Queries Executed by Hibernate?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-21 07:31:39832browse

How Can I See the Exact SQL Queries Executed by Hibernate?

How to view the actual SQL query in Hibernate

While setting hibernate.show_sql=true in the configuration file can display SQL queries, these queries may not accurately reflect the queries ultimately sent to the database. If you need to see the actual SQL code, there are several ways.

Use JDBC driver proxy

Tools like P6Spy or log4jdbc can act as a JDBC-driven proxy, allowing you to intercept and format SQL queries sent to the database.

Enable logging

Alternatively, you can enable logging in log4j.properties for the following categories:

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

This will log the SQL query in a format similar to your example, including bind parameters:

<code>select employee.code from employee where employee.code=12</code>

Reference materials

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

Statement:
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