Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make hbm2ddl schemaExport to log schema to stdout?

A quote from persistence.xml:

<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
    <properties>
        <property name="hibernate.archive.autodetection" value="class" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="create" />
        ...
    </properties>
</persistence-unit>

This is what I see in log output:

Sep 30, 2010 12:03:43 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
Sep 30, 2010 12:03:43 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
Sep 30, 2010 12:03:43 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete

But I don't see the schema (SQL) exported itself. How to get this information out of Hibernate (3.5.6-Final)?

like image 709
yegor256 Avatar asked Sep 30 '10 10:09

yegor256


1 Answers

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).

like image 174
Pascal Thivent Avatar answered Oct 14 '22 12:10

Pascal Thivent