我正在尝试从映射 xml 文件生成 POJO。我读过一些关于添加蚂蚁任务的内容,以轻松完成它。

我已将此 xml 添加到 Netbeans 中项目的 build-impl.xml 中,但没有任何反应:

<target name="codegen">
     <echo>Zippzip</echo>
    <taskdef name="hbm2java"
             classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
             classpathref="javac.classpath"/>
    <hbm2java 
              output="generated/src/">
        <fileset dir="cat/model/">
            <include name="**/*.hbm.xml"/>
        </fileset>
    </hbm2java>
</target>

我是 Netbeans、Ant 和 Hibernate 的初学者,有人可以帮助我吗?

附:我真的不知道“classpathref”应该是什么。我的意思是我知道它应该包含休眠发行版的类路径。真正的问题是我不知道如何让 Ant 任务工作。

编辑:我发现上面的脚本不适用于 Hibernate3..我有另一个脚本,但仍然不起作用。显示的错误消息是:无法创建 hibernatetool 类型,因为类 org.hibernate.tool.ant.Hbm2JavaExporterTask 没有兼容的构造函数;和脚本:

<target name="codegen">
    <taskdef name="hibernatetool"
        classname="org.hibernate.tool.ant.Hbm2JavaExporterTask">
        <classpath refid="project.classpath" />
    </taskdef>

    <hibernatetool destdir="cat/model/">
        <configuration configurationfile="hibernate.cfg.xml"/>
        <hbm2java />
    </hibernatetool>
</target>

正如我在 hibernate 文档中看到的那样,这是 Hibernate3 兼容的: http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html/ant.html#d0e2903

有帮助吗?

解决方案

我不知道调用:hbm2java但添加任务如上面的代码后,任何东西,你需要添加与此相关联的蚂蚁的罐子。这是通过复制jar文件inton $ANT_HOME/lib目录来完成的。你这样做吗?

其他提示

弄清楚:应该将 'org.hibernate.tool.ant.Hbm2JavaExporterTask' 替换为 'org.hibernate.tool.ant.HibernateToolTask​​'

这是我如何使用它。       

    <hibernatetool destdir="${src.java.dir}">
        <configuration>
            <fileset dir="${src.java.dir}">
                <include name="**/*.hbm.xml"/>
            </fileset>
        </configuration>
        <hbm2java/> <!-- Generate POJO source -->
    </hibernatetool>

</target>

你有没有用的,而不是XML JPA注解考虑?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top