来自persistence.xml:
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)中获取此信息?
将org.hibernate.tool.hbm2ddl类别的日志记录激活为DEBUG。
org.hibernate.tool.hbm2ddl
DEBUG
更新: 这是一个简化的logback.xml(我使用logback作为日志记录后端):
logback.xml
<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,请对其进行调整(在SO上可以找到有效的配置)。