【Xdoclet + ant自动生成Hibernate配置文件】

在使用Hibernate的时候,过多的Hibernate配置文件是一个让人头疼的问题。最近接触了Xdoclet这个工具。它实际上就是一个自动代码生成的工具,Xdoclet不能单独运行,必须搭配其他工具一起使用,比如ant.如果ant的工具不会用,建议先补充一下ant的基本知识在来学习Xdoclet.

    1.首先保证本机器上的ant是可用的。

    2.下载Xdoclet,解压。

    3.在ant的build.xml中定义xdoclet任务

    在这里我们做的是根据hibernate实体类生成hibernate映射文件,所以得先有Hibernate的实体类。

    [java]

    /**

    * @hibernate.class

    *      table="T_Party"

    */

    public class Party {

    /**

    * @hibernate.id

    *      generator-class="native"

    */

    private int id;

    /**

    * @hibernate.many-to-one

    *      column="parentid"

    */

    private Party parent;

    /**

    * @hibernate.set

    * @hibernate.key

    *   column = "parentid"

    * @hibernate.one-to-many

    *      class = "com.bjsxt.oa.model.Party"

    */

    private Set children;

    /**

    * @hibernate.property

    *      column="thename"

    */

    private String name;

    /**

    * @hibernate.property

    */

    private String sn;

    /**

    * @hibernate.property

    */

    private String description;

    /**

    *

    * @return

    */

    public Set getChildren() {

    return children;

    }

    public void setChildren(Set children) {

    this.children = children;

    }

    public String getDescription() {

    return description;

    }更多精彩教程请关注:免费windows xp电脑系统和xp系统下载基地

posted on 2013-08-05 09:31  潇洒kman  阅读(129)  评论(0编辑  收藏  举报