小弟今天使用 Java 类中的 Hibernate 注释标签结合 xdoclet 工具生成 .hbm.xml 映射文件。
现在小弟遇到一个不解的问题,为了表述得更清晰一些,特将代码简要公示一下。类文件:
/**
 * @hibernate.mapping default-lazy="false"
 * @hibernate.meta attribute="class-description" value="图书"
 * @hibernate.class table="bk_ts"
 */
public class Book {
    private Long id; // 标识
    /**
     * @hibernate.id generator-class="native" column="id"
     * @hibernate.meta attribute="field-description" value="标识"
     */
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    ... ...
}Ant 文件:
<project name="teset" default="generate-mapping" basedir="."><path id="xdoclet.classpath">
    <fileset dir="${lib.dir}" includes="*.jar"/>
</path><target name="xdoclet">
    <taskdef name="hibernatedoclet"
             classname="xdoclet.modules.hibernate.HibernateDocletTask"
     classpathref="xdoclet.classpath"
    />
</target><target name="generate-mapping" depends="define-tasks">
    <hibernatedoclet destdir="${dao.dir}" verbose="true" force="true">
        <fileset dir="${dao.dir}">
            <include name="**/model/*.java"/>
        </fileset>
        <hibernate version="3.0" xmlencoding="gb2312"/>
    </hibernatedoclet>
</target></project>类路径 xdoclet.classpath :
包含的是 xdoclet-bin-1.2.3.zip 中的相关 .jar 包。生成 .hbm.xml 文件:
<?xml version="1.0" encoding="gb2312"?><!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping>
    <class
        name="name.daviddai.ehome.model.Book"
        table="bk_ts"
    >
    <id
        name="id"
        column="id"
        type="java.lang.Long"
    >
        <generator class="native">
            <!--  
                To add non XDoclet generator parameters, create a file named 
                hibernate-generator-params-Book.xml 
                containing the additional parameters and place it in your merge dir. 
            --> 
        </generator>
    </id>
    ... ...
</hibernate-mapping>问题说明:
    很明显,类文件中的 @hibernate.meta attribute="field-description" value="标识" 的定义没有在 .hbm.xml 文件中产生对应结果。也就是说 .hbm.xml 文件中缺少 <meta attribute="field-description">标识</meta> 的信息。
    我使用 Ant 脚本和 Myeclipse 的 xdoclet 插件都试过,但是得到的结果都一样,不知道为什么。
    如果使用 Myeclipse 的 xdoclet 插件来生成怎么配置呢?如果用 Ant 的话,我的脚本需要怎么修改呢?或者说我用的 xdoclet 版本有什么问题呢?
    请各位大哥大姐不吝赐教,万分感激!

解决方案 »

  1.   

    解决方案参见
    http://flysnow.javaeye.com/blog/599116另可以参见
    http://opensource.atlassian.com/projects/xdoclet/browse/XDT-1312
      

  2.   

    十分感谢您的回答,我现在才回到住处能够上网,所有结贴晚了点,敬请原谅。
    您回答的方案我已经试过了,基本是这个原因,就是自带包的问题,但是现在出现了一个新状况,就是加入这个新的 xdoclet-hibernate-module-1.2.3 包以后 Myeclipse 在生成 .hbm 文档时总是死机,等在那里,请问这是什么情况呢?谢谢了!
      

  3.   

    经过进一步的测试是因为不能放中文,也就是说不能写成 @hibernate.meta attribute="field-description" value="标识" 而只能写成 @hibernate.meta attribute="field-description" value="ID" 否则,Myeclipse 就会出现 waiting for virtual machine to exit 信息,进程一直等在那里。然后文件的的中文会出现乱码,请问 ls8707 这些情况您都遇到过没有。谢谢!
      

  4.   

    你看看这个,希望有助于你~
    http://lavasoft.blog.51cto.com/62575/12545