How to print hibernate-generated SQL statements to a log file

Source: Internet
Author: User
Tags log4j

Background: project development needs.

1 operation

Just add the following two lines of code to the Log4j.properties

#输出sql语句到日志  Log4j.logger.org.hibernate.SQL=Debug    #将对应的参数占位符? Replace with incoming parameter  log4j.logger.org.hibernate.type=trace

Experimental results:

 .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] DEBUG Org.hibernate.SQL (104) -Selectcpsysparm0_. CODE ascode65_0_, Cpsysparm0_.name asname65_0_, cpsysparm0_. Parmvalue asparmvalue65_0_, cpsysparm0_. Parmdesc asparmdesc65_0_, cpsysparm0_. Modifiable asmodifiable65_0_, cpsysparm0_. Viewable asviewable65_0_, cpsysparm0_. Operuser asoperuser65_0_, cpsysparm0_. Opertime asopertime65_0_ fromcp_sysparm cpsysparm0_wherecpsysparm0_. CODE=? .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] TRACE Org.hibernate.type.descriptor.sql.BasicBinder ( the)-Binding parameter [1] as[VARCHAR]-012 .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] TRACE Org.hibernate.type.descriptor.sql.BasicExtractor ( the)-Found [current matches] ascolumn [name65_0_] .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] TRACE Org.hibernate.type.descriptor.sql.BasicExtractor ( the)-Found [1] ascolumn [parmvalue65_0_] .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] TRACE Org.hibernate.type.descriptor.sql.BasicExtractor ( the)-Found [NULL] ascolumn [parmdesc65_0_] .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] TRACE Org.hibernate.type.descriptor.sql.BasicExtractor ( the)-Found [0] ascolumn [modifiable65_0_] .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] TRACE Org.hibernate.type.descriptor.sql.BasicExtractor ( the)-Found [1] ascolumn [viewable65_0_] .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] TRACE Org.hibernate.type.descriptor.sql.BasicExtractor ( the)-Found [init] ascolumn [operuser65_0_] .- the- to  -:Wuyi: -[dubboserverhandler-thread-1] TRACE Org.hibernate.type.descriptor.sql.BasicExtractor ( the)-Found [ .- One- at Ten: .:47.0] ascolumn [opertime65_0_]

You can see that the process and results of the query are output.

How to print hibernate-generated SQL statements to a log file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.