How to make hbm2ddl schemaExport to log schema to stdout?

与世无争的帅哥 提交于 2019-11-30 11:22:53

Activate the logging of the org.hibernate.tool.hbm2ddl category to DEBUG.


Update: Here is a simplified logback.xml (I'm using logback as logging backend):

<configuration scan="true">

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
    </layout>
  </appender>

  <!-- ### log just the SQL ### -->
  <logger name="org.hibernate.SQL" level="DEBUG"/>

  <!-- ### log JDBC bind parameters ### -->
  <logger name="org.hibernate.type" level="TRACE"/>

  <logger name="org.hibernate.tool.hbm2ddl" level="DEBUG"/>

  <root level="ERROR">
    <appender-ref ref="STDOUT"/>
  </root>
</configuration>

Adapt it if you are using log4j (you'll find working configuration here on SO).

Just in case you stumble upon this using Spring Boot. You can configure the following in your application.yml:

spring.jpa:
  hibernate.ddl-auto: create-drop
logging.level:               
  org.hibernate.tool.hbm2ddl: DEBUG
  org.hibernate.SQL: DEBUG   
  org.hibernate.type: TRACE  

Here is a simplified log4j.xml configuration.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
    <appender name="CA" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n"/>
        </layout>
    </appender>
    <!-- ### log just the SQL ### -->
    <logger name="org.hibernate.SQL">
        <level value="DEBUG" />
    </logger>
    <!-- ### log JDBC bind parameters ### -->
    <logger name="org.hibernate.type">
        <level value="TRACE" />
    </logger>
    <!-- ### log Hibernate model to schema tool ### -->
    <logger name="org.hibernate.tool.hbm2ddl">
        <level value="DEBUG" />
    </logger>
    <root>
        <level value="WARN"/>
        <appender-ref ref="CA"/>
    </root>
</log4j:configuration>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!