我使用 Hibernate 自动生成我的数据库以进行测试,我的模式中有一些表包含需要很长时间才能导入的静态数据。过去,我在构建文件中使用以下代码生成数据库(从映射文件):
<target name="schema-gen" depends="hibernate-gen">
<taskdef name="schemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="project.classpath" />
<schemaexport properties="resources/hibernate.properties" text="false" quiet="false" delimiter=";" output="schema.sql">
<fileset dir="${build.doclets}">
<include name="**/*.hbm.xml" />
<exclude name="**/inert/*.hbm.xml" />
</fileset>
</schemaexport>
</target>
.hbm.xml 文件是使用 XDoclet 生成的。我正在迁移到使用 Hibernate Annotations 进行映射,所以我正在迁移到 hibernatetools 来生成模式:
<target name="annotations-export" depends="hibernate-gen">
<hibernatetool destdir="${basedir}">
<annotationconfiguration configurationfile="${basedir}/resources/hibernate.cfg.xml" propertyfile="${basedir}/resources/hibernate.properties" />
<classpath>
<path refid="project.classpath" />
</classpath>
<hbm2ddl drop="true" create="true" export="true" outputfilename="schema.sql" delimiter=";" format="true" />
</hibernatetool>
</target>
我希望能够告诉 hbm2ddl 省略“惰性”包中的类,就像我以前使用 schemaexport 一样。任何人都知道是否有办法做到这一点?
最佳答案
这应该有效:
<target name="annotations-export" depends="hibernate-gen">
<hibernatetool destdir="${basedir}">
<annotationconfiguration configurationfile="${basedir}/resources/hibernate.cfg.xml" propertyfile="${basedir}/resources/hibernate.properties">
<fileset dir="${build.doclets}">
<include name="**/*.class" />
<exclude name="**/inert/*.class" />
</fileset>
</annotationconfiguration>
<classpath>
<path refid="project.classpath" />
</classpath>
<hbm2ddl drop="true" create="true" export="true" outputfilename="schema.sql" delimiter=";" format="true" />
</hibernatetool>
</target>
关于java - 有没有办法让 Hibernate 的 hbm2ddl Ant 任务排除特定的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2140709/