如何使 hbm2ddl schemaExport 将模式记录到标准输出?

发布于 2024-09-25 16:39:58 字数 945 浏览 5 评论 0原文

引用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>

这是我在日志输出中看到的:

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

但我没有看到模式(SQL)导出本身。如何从 Hibernate (3.5.6-Final) 中获取此信息?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你列表最软的妹 2024-10-02 16:39:58

org.hibernate.tool.hbm2ddl 类别的日志记录激活为 DEBUG


更新:这是一个简化的logback.xml(我使用logback作为日志记录后端):

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

如果您使用log4j,请调整它(您可以在此处找到工作配置)所以)。

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

妄想挽回 2024-10-02 16:39:58

以防万一您使用 Spring Boot 偶然发现这一点。您可以在 application.yml 中配置以下内容:

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

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  
陪你搞怪i 2024-10-02 16:39:58

这是一个简化的 log4j.xml 配置。

<?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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文