天天看点

XDoclet 生成 *.hbm.xml文件

第一步 下载XDoclet-1.2.3

第二步 配置bulid.xml

[quote]

<?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" /> //配置生成文件的路径 可以使用 **

public class CustomerVO implements Serializable {

private java.lang.Integer id;

private String name;

private java.lang.Integer age;

private Set orders;

public CustomerVO(java.lang.String name, java.lang.Integer age, Set orders) {

this.name = name;

this.age = age;

this.orders = orders;

}

public CustomerVO() {

}

public CustomerVO(Set orders) {

this.orders = orders;

}

public java.lang.Integer getId() {

return this.id;

}

public void setId(java.lang.Integer id) {

this.id = id;

}

public java.lang.String getName() {

return this.name;

}

public void setName(java.lang.String name) {

this.name = name;

}

public java.lang.Integer getAge() {

return this.age;

}

public void setAge(java.lang.Integer age) {

this.age = age;

}

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();

}

}

[/quote]

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

[quote]

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

[/quote]