在以前的项目hbm2ddl
中,我使用任务hibernate3-maven-plugin
生成 DDL 代码 - 我在启用调试输出的情况下运行 maven 任务,并且 DDL 以可粘贴的方式记录到控制台。事实上,我使用此代码作为部署的初始迁移。配置是这样的:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<configuration>
<hibernatetool>
<annotationconfiguration
configurationfile="src/main/resources/db/database/config/annotatedhibernate.cfg.xml"
propertyfile="src/main/resources/db/database/config/hibernate.properties" />
<hbm2ddl drop="true" create="true" delimiter=";" format="true" console="true" outputfilename="output.ddl" />
</hibernatetool>
</configuration>
现在我发现spring-data-jpa
并配置了它HibernateJpaVendorAdapter
来生成我的 DDL 代码。很快我希望部署并喜欢将可粘贴的 DDL 代码记录到控制台(或某处),但我只知道如何设置和配置休眠日志记录,并且能够设置日志级别和内容 - 但美丽的 DDL 就像在maven 调试永远不会出现。如何使用 HibernateJpaVendorAdapter 启用它。当前配置如下:
<bean id="hibernateJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="showSql" value="true" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan" value="my.recipes.api.impl" />
</bean>