XDoclet 生成 *.hbm.xml文件

第一步 下载XDoclet-1.2.3
第二步 配置bulid.xml
引用

<?xml version="1.0"?>
<project name="Hibernate" default="hibernate" basedir=".">
<property name="xdoclet.lib.home" value="C:\xdoclet-1.2.3\lib" /> //配置doclet的目录
<target name="hibernate" depends="" description="Generates Hibernate class descriptor files.">
<taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask">
<classpath>
<fileset dir="${xdoclet.lib.home}">
<include name="*.jar" />
</fileset>
</classpath>
</taskdef>
<hibernatedoclet destdir="./src/" excludedtags="@version,@author,@todo" force="true" verbose="true" mergedir=".">
<fileset dir="./src/">
<include name="com/cncsys/model/CustomerVO.java" /> //配置生成文件的路径 可以使用 **/*.java
</fileset>
<hibernate version="2.0" /> //我这里用到2.0 3.0没有试验过
</hibernatedoclet>
</target>
</project>


配置java文件 在java文件中配置javadoc内容
CustomerVO.java
引用

package com.cncsys.model;

import java.io.Serializable;
import java.util.Set;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
*        @hibernate.class
*         table="CUSTOMERS"
*    
*/
public class CustomerVO implements Serializable {

    /** identifier field */
    private java.lang.Integer id;

    /** nullable persistent field */
    private String name;

    /** nullable persistent field */
    private java.lang.Integer age;

    /** persistent field */
    private Set orders;

    /** full constructor */
    public CustomerVO(java.lang.String name, java.lang.Integer age, Set orders) {
        this.name = name;
        this.age = age;
        this.orders = orders;
    }

    /** default constructor */
    public CustomerVO() {
    }

    /** minimal constructor */
    public CustomerVO(Set orders) {
        this.orders = orders;
    }

    /**
     *            @hibernate.id
     *             generator-class="sequence"
     *             type="java.lang.Integer"
     *             column="ID"
     *            @hibernate.generator-param
     *            name="sequence"
     *            value="HIBERNATE_SEQUENCE"
     *        
     */
    public java.lang.Integer getId() {
        return this.id;
    }

    public void setId(java.lang.Integer id) {
        this.id = id;
    }

    /**
     *            @hibernate.property
     *             column="NAME"
     *             length="15"
     *        
     */
    public java.lang.String getName() {
        return this.name;
    }

    public void setName(java.lang.String name) {
        this.name = name;
    }

    /**
     *            @hibernate.property
     *             column="AGE"
     *             length="22"
     *        
     */
    public java.lang.Integer getAge() {
        return this.age;
    }

    public void setAge(java.lang.Integer age) {
        this.age = age;
    }

    /**
     *            @hibernate.set
     *             lazy="true"
     *             cascade="save-update"
     *            @hibernate.collection-key
     *             column="CUSTOMER_ID"
     *            @hibernate.collection-one-to-many
     *             class="com.cncsys.model.Order"
     *        
     */
    public java.util.Set getOrders() {
        return this.orders;
    }

    public void setOrders(java.util.Set orders) {
        this.orders = orders;
    }

    public String toString() {
        return new ToStringBuilder(this)
            .append("id", getId())
            .toString();
    }

    public boolean equals(Object other) {
        if ( !(other instanceof CustomerVO) ) return false;
        CustomerVO castOther = (CustomerVO) other;
        return new EqualsBuilder()
            .append(this.getId(), castOther.getId())
            .isEquals();
    }

    public int hashCode() {
        return new HashCodeBuilder()
            .append(getId())
            .toHashCode();
    }

}


第三步 在eclipse中执行bulid.xml在指定目录下生成对应的*.hbm.xml
引用

Buildfile: C:\eclipse\workspace\******\build.xml
hibernate:
[hibernatedoclet] (XDocletMain.start                   47  ) Running <hibernate/>
[hibernatedoclet] Generating mapping file for com.cncsys.model.CustomerVO.
[hibernatedoclet] com.cncsys.model.CustomerVO
BUILD SUCCESSFUL
Total time: 2 seconds

你可能感兴趣的:(java,apache,eclipse,xml,Hibernate)