---
title: "xdoclet2  例子"
author: "hwpok"
date: "2008-10-20T19:21:00Z"
tags: []
slug: "xdoclet2"
draft: false
lastmod: "2008-10-20T19:21:00Z"
id: 615812
url: "https://hwpok.iteye.com/blog/615812"
---

Customer.java

&lt;!--&lt;br /&gt; &lt;br /&gt; Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt; http://www.CodeHighlighter.com/&lt;br /&gt; &lt;br /&gt; --&gt;package org.roadway.wisp.test;

import java.io.Serializable;  
import java.util.Date;  
import java.util.HashSet;

/\**  
 * @hibernate.class table="ZD\_COSTOMER"  
 \*/  
public class Customer implements Serializable  
{  
    private static final long serialVersionUID = 939548333216539319L;  
      
    private Long              customerId;  
      
    private String            customerName;  
      
    private Date              birthday;  
      
    private HashSet&lt;Order&gt;    orders;  
      
    /\**  
     * @hibernate.id generator-class="sequence" column="CUSTOMER\_ID"  
     *               unsaved-value = "null"  
     * @hibernate.generator-param name="sequence" value="SQ\_PERSON\_ID"  
     *   
     * @return  
     \*/  
    public Long getCustomerId()  
    {  
        return customerId;  
    }  
      
    /\**  
     * @hibernate.property column="CUSTOMER\_NAME" length="32" not-null="true"  
     \*/  
    public String getCustomerName()  
    {  
        return customerName;  
    }  
      
    /\**  
     * @hibernate.property column="BIRTHDAY"  
     \*/  
    public Date getBirthday()  
    {  
        return birthday;  
    }  
      
    /\**  
     * @hibernate.set table="ZD\_ORDER" lazy="true" inverse="true"  
     * @hibernate.key column="CUSTOMER\_ID"  
     * @hibernate.one-to-many class="org.roadway.wisp.test.Order"  
     \*/  
    public HashSet&lt;Order&gt; getOrders()  
    {  
        return orders;  
    }  
      
    public void setCustomerId(Long customerId)  
    {  
        this.customerId = customerId;  
    }  
      
    public void setCustomerName(String customerName)  
    {  
        this.customerName = customerName;  
    }  
      
    public void setBirthday(Date birthday)  
    {  
        this.birthday = birthday;  
    }  
      
    public void setOrders(HashSet&lt;Order&gt; orders)  
    {  
        this.orders = orders;  
    }  
}

Order.java

&lt;!--&lt;br /&gt; &lt;br /&gt; Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt; http://www.CodeHighlighter.com/&lt;br /&gt; &lt;br /&gt; --&gt;package org.roadway.wisp.test;

import java.io.Serializable;

/\**  
 * @hibernate.class table="ZD\_ORDER"  
 \*/  
public class Order implements Serializable  
{  
    private static final long serialVersionUID = 8989273619109202636L;  
      
    private Long              orderId;  
      
    private String            orderName;  
      
    private Double            money;  
      
    private Customer          customer;  
      
    /\**  
     * @hibernate.id generator-class="sequence" column="ORDER\_ID" unsaved-value =  
     *               "null"  
     * @hibernate.generator-param name="sequence" value="SQ\_ORDER\_ID"  
     *   
     * @return  
     \*/  
    public Long getOrderId()  
    {  
        return orderId;  
    }  
      
    /\**  
     * @hibernate.property column="ORDER\_NAME" length="32" not-null="true"  
     \*/  
    public String getOrderName()  
    {  
        return orderName;  
    }  
      
    /\**  
     * @hibernate.property column="MONEY" not-null="true"  
     \*/  
    public Double getMoney()  
    {  
        return money;  
    }  
      
    /\**  
     * @hibernate.many-to-one column="teacher\_id" not-null="true"  
     \*/  
    public Customer getCustomer()  
    {  
        return customer;  
    }  
}

xdoclet.xml

&lt;!--&lt;br /&gt; &lt;br /&gt; Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt; http://www.CodeHighlighter.com/&lt;br /&gt; &lt;br /&gt; --&gt;&lt;?xml version="1.0"?&gt;  
&lt;project name="xdoclet" default="hibernate.mapping.generate" basedir="."&gt;  
    &lt;property name="project.src" value="test"/&gt;  
    &lt;property name="po.package" value="org/roadway/wisp/test"/&gt;  
    &lt;property name="xdoclet.lib" value="E:/user\_hvp/xdoclet-plugins-dist-1.0.4/lib"/&gt;  
    &lt;path id="xdoclet.task.classpath"&gt;  
        &lt;fileset dir="${xdoclet.lib}"&gt;  
            &lt;include name="\*.jar" /&gt;  
        &lt;/fileset&gt;  
        &lt;pathelement location="${xdoclet.lib}/xdoclet-plugin-hibernate-1.0.4.jar" /&gt;  
    &lt;/path&gt;  
    &lt;taskdef name="xdoclet" classname="org.xdoclet.ant.XDocletTask" classpathref="xdoclet.task.classpath" /&gt;  
    &lt;target name="hibernate.mapping.generate"&gt;  
        &lt;xdoclet&gt;  
            &lt;fileset dir="${project.src}"&gt;  
                &lt;include name="${po.package}/\*.java" /&gt;  
            &lt;/fileset&gt;  
            &lt;component classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin" destdir="${basedir}/${project.src}" version="3.0" /&gt;  
        &lt;/xdoclet&gt;  
    &lt;/target&gt;  
&lt;/project&gt;

xdoclet1.x不支持泛型,xdoclet2支持!!