java - 有没有办法让 Hibernate 的 hbm2ddl Ant 任务排除特定的表?

标签 java hibernate ant annotations hbm2ddl

我使用 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/

相关文章:

java - 如何在不使用任务监听器的情况下获取 Firebase Auth Token?

java - 使用 Selenium Webdriver 找不到特定标签

regex - 根据文件中的正则表达式设置 Ant 属性

java - 预编译jsp文件发生异常

c# - 如何从C#编译Java?

java - 四舍五入的双重陌生感

java - 对象枚举总是返回空值

hibernate - 同一个表上的多对多与附加列

java - 将连接表引用到 View

java - 在 Tomcat 上部署后显示应用程序上下文路径