如何使hbm2ddl schemaExport将模式记录到stdout? [英] How to make hbm2ddl schemaExport to log schema to stdout?

查看:158
本文介绍了如何使hbm2ddl schemaExport将模式记录到stdout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 persistence.xml 的引述:

 <持续性-unit name =testtransaction-type =RESOURCE_LOCAL> 
<属性>
< property name =hibernate.archive.autodetectionvalue =class/>
< property name =hibernate.show_sqlvalue =true/>
< property name =hibernate.format_sqlvalue =true/>
< property name =hibernate.hbm2ddl.autovalue =create/>
...
< / properties>
< / persistence-unit>

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

  2010年9月30日下午12:03:43 org.hibernate.tool.hbm2ddl.SchemaExport执行
INFO:运行hbm2ddl模式导出
2010年9月30日12:03:43 PM org.hibernate.tool.hbm2ddl.SchemaExport执行
INFO:将生成的模式导出到数据库
2010年9月30日下午12:03:43 org.hibernate.tool.hbm2ddl.SchemaExport执行
INFO:模式导出完成

但是我没有看到模式(SQL)导出自己。如何从Hibernate(3.5.6-Final)中获取这些信息?

解决方案

激活记录 org.hibernate.tool.hbm2ddl 类别到 DEBUG






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

 < configuration scan =true> 

< appender name =STDOUTclass =ch.qos.logback.core.ConsoleAppender>
< layout class =ch.qos.logback.classic.PatternLayout>
<模式>%d {HH:mm:ss.SSS} [%线程]%-5级别记录器{36} - %msg%n< / Pattern>
< / layout>
< / appender>

<! - ###只记录SQL ### - >
< logger name =org.hibernate.SQLlevel =DEBUG/>

<! - ### log JDBC绑定参数### - >
< logger name =org.hibernate.typelevel =TRACE/>

< logger name =org.hibernate.tool.hbm2ddllevel =DEBUG/>

< appender-ref ref =STDOUT/>
< / root>
< / configuration>

如果您使用的是log4j,则适应它(您将在SO上找到工作配置) p>

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

解决方案

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

这篇关于如何使hbm2ddl schemaExport将模式记录到stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆