Hibernate how to view automatically generated build statements in the console

Source: Internet
Author: User
Tags log4j

Hibernate automatically builds tables by configuring <property name= "Show_sql" >true</property> and <property name= "Hbm2ddl.auto" > Create</property> can automatically build a table and display the statement that inserts the data in the console, but cannot display the build statement, This is because hibernate comes with the log Environment Slf4j-api interface Implementation JAR Package Slf4j-nop-1.5.8.jar is not perfect, SLF4J-API interface is implemented in many ways, to display the table statements need to use log4j jar package to implement SLF4J-API interface, because Log4j cannot implement the Slf4j-api interface directly also requires a translator Slf4j-log4j12-1.5.8.jar.

So you can implement the console display statement by simply doing the following:

1. Remove the original Slf4j-nop-1.5.8.jar join Log4j-1.2.15.jar

2. and add the converter Slf4j-log4j12-1.5.8.jar

3. Of course, you must also put the interface: Slf4j-api-1.5.8.jar

4. In the catalogue hibernate-distribution-3.6.0.final-dist\hibernate-distribution-3.6.0.final\project\ etc, locate the file log4j.properties, copy it to the project SRC directory and open it,

You can find the statement: Log4j.logger.org.hibernate.tool.hbm2ddl=debug, which is the configuration used to display the DDL statements, and other configurations to display other information, not to comment out

5. Run the program to view the table statement printed by the console.

Note: Slf4j-log4j12-1.5.8.jar and Slf4j-api-1.5.8.jar are in the same SLF4J official Download version folder

Download website:

http://www.slf4j.org/dist/

Http://logging.apache.org/log4j/1.2/download.html

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.