Hibernate 4.0 hibernatetool taskdef 错误

标签 hibernate hbm2ddl

我正在使用 hibernate 4.0.0.CR4 并尝试使用 Java Persistence with Hibernate 中的“消息”示例。我能够使用 ant build 编译和运行应用程序,但是当我尝试使用 hibernatetool 导出模式时,出现错误

构建文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="HelloWorld" default="compile"  basedir=".">
    <property name="proj.name" value="HelloWorld"/>
    <property name="proj.version" value="1.0"/>

    <!-- Global properties for this build  -->
    <property name="src.java.dir" value="src"/>
    <property name="lib.dir" value="lib"/>
    <property name="build.dir" value="bin"/>

    <path id="project.classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
            <include name="**/*.zip"/>
        </fileset>
    </path>

    <!-- Useful shortcuts -->
    <patternset id="meta.files">
        <include name="**/*.xml"/>
        <include name="**/*.properties"/>
    </patternset>

    <!-- Cleanup -->
    <target name="clean">
        <delete dir="${build.dir}"/>
        <mkdir dir="${build.dir}"/>
    </target>

    <!-- Compile Java source -->
    <target name="compile" depends="clean">
        <mkdir dir="${build.dir}"/>
        <javac
            srcdir="${src.java.dir}"
            destdir="${build.dir}"
            nowarn="on">
            <classpath refid="project.classpath"/>
        </javac>
    </target>

    <!-- Copy metadata to build classpath -->
    <target name="copymetafiles">
        <copy todir="${build.dir}">
            <fileset dir="${src.java.dir}">
                <patternset refid="meta.files"/>
            </fileset>
        </copy>
    </target>

    <!--Run HelloWorld -->
    <target name="run" depends="compile, copymetafiles"
        description="Build and run HelloWorld">
        <java fork="true"
            classname="hello.HelloWorld"
            classpathref="project.classpath">
            <classpath path="${build.dir}"/>
        </java>
    </target>
    <!-- SchemaExporter -->
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
        classpathref="project.classpath"/>
    <target name="schemaexport" depends="compile, copymetafiles"
        description="Exports a generated schema to DB and files">
        <hibernatetool destdir="${basedir}">
            <classpath path="${build.dir}"/>
            <configuration configurationfile="${build.dir}/hibernate.cfg.xml"/>
            <hbm2ddl
                drop="true"
                create="true"
                export="true"
                outputfilename="helloworld-ddl.sql"
                delimiter=";"
                format="true"/>
        </hibernatetool>
    </target>
</project>

错误:
/home/student/workspace/HelloWorld/build.xml:61: taskdef A class needed by class org.hibernate.tool.ant.EnversHibernateToolTask cannot be found: org/hibernate/tool/ant/HibernateToolTask

以下是我的类(class)路径上的 jar :
antlr-2.7.7.jar
同学-0.5.4.jar
commons-collections-3.2.1.jar
commons-logging-1.1.1.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.0.CR2.jar
hibernate-core-4.0.0.CR4.jar
hibernate-envers-4.0.0.CR4.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
数据库文件
jandex-1.0.3.Final.jar
javassist-3.12.1.GA.jar
jboss-logging-3.0.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar

在几个论坛上,我发现缺少的类是 hibernate-tools.jar 的一部分,但我在 hibernate 版本中找不到这个 jar (http://sourceforge.net/projects/hibernate/files/hibernate4/4.0.0 .CR4/)

最佳答案

您应该将节点设置在

<target name="schemaexport" depends="compile, copymetafiles"
    description="Exports a generated schema to DB and files">
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
        classpathref="project.classpath"/>

    <hibernatetool destdir="${basedir}">
        <classpath path="${build.dir}"/>
        <configuration configurationfile="${build.dir}/hibernate.cfg.xml"/>
        <hbm2ddl
            drop="true"
            create="true"
            export="true"
            outputfilename="helloworld-ddl.sql"
            delimiter=";"
            format="true"/>
    </hibernatetool>
</target>

关于Hibernate 4.0 hibernatetool taskdef 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7827106/

相关文章:

java - 分离如何在持久化实体的事务方法中工作

java - 野蝇 - @TransactionAttribute -

java - spring部署在Tomcat中时是否需要JTA TX管理器

mysql - 在 Mysql 上使用 ddl 模式生成时未生成 ON DELETE CASCADE 选项

hibernate - 具有多个数据库供应商支持的 Java/Maven/JPA/Hibernate 构建的最佳方法?

java - Hibernate session 不更新实体

java - JPA - 关闭 EntityManagerFactory 引发异常

java - 如何使用 HBM 映射创建两列唯一键约束?

database - 数据库迁移 - Hibernate/JPA - hbm2ddl - diff 工具

spring - Maven + Spring + hibernate : hibernate3-maven-plugin hbm2ddl fails for reason "Caused by: java.lang.NullPointerException"