Home > Database > Mysql Tutorial > How Can I View the Actual Raw SQL Queries Executed by Hibernate?

How Can I View the Actual Raw SQL Queries Executed by Hibernate?

Susan Sarandon
Release: 2025-01-21 07:42:09
Original
406 people have browsed it

How Can I View the Actual Raw SQL Queries Executed by Hibernate?

Hibernate - View raw SQL query

Question

In the hibernate.cfg.xml configuration file, setting show_sql to true will display SQL statements on the console. However, this is not the "real" SQL passed to the database. Is it possible to get the original SQL query?

Answer

Yes, there are two ways to get the raw SQL query:

JDBC Driver Proxy:

Use a JDBC driver proxy such as P6Spy or log4jdbc. These tools intercept SQL commands sent to the database and provide detailed information, including the actual SQL query.

Hibernate logging:

Enable logging for the following categories:

<code>log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE</code>
Copy after login
  • org.hibernate.SQL=DEBUG: Equivalent to hibernate.show_sql=true, it displays SQL queries.
  • org.hibernate.type=TRACE: Prints binding parameters, providing further insight into SQL queries.

Reference

  • Hibernate 3.5 core documentation:

  • Hibernate 4.1 core documentation:

The above is the detailed content of How Can I View the Actual Raw SQL Queries Executed by Hibernate?. 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