XDoclet2+Hibernate3

步骤:
1.下载 XDoclet2,如xdoclet-plugins-1.0.2.zip
    下载Hibernate3,如hibernate-3.2.4.sp1.zip
2.写源码如 Event.java
package events;

import java.util.*;

/**
 * @author martin
 * @version 1.0
 * @hibernate.class table="EVENTS"
 */
public class Event {
    private Long id;

    private String title;
    private Date date;

    public Event() {}

/** The getter method for this Customer's identifier.
      *
      * @hibernate.id  generator-class="native" name="id" column="EVENT_ID"   
      */
    public Long getId() {
        return id;
    }

    private void setId(Long id) {
        this.id = id;
    }
/** The getter method for this Customer's name
      *
      * @hibernate.property type="timestamp" column="EVENT_DATE"
      */
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
/** The getter method for this Customer's name
      *
      * @hibernate.property
      */
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
   

    private Set participants = new HashSet();
    /**
     * @hibernate.set table="PERSON_EVENT" inverse="true"
     * @hibernate.key column="EVENT_ID"
     * @hibernate.many-to-many column="PERSON_ID" class="events.Person"
     */
    public Set getParticipants() {
        return participants;
    }

    public void setParticipants(Set participants) {
        this.participants = participants;
    }

}
3.建立lib文件夹放入所需的包
ant-contrib-1.0b1.jar
commons-beanutils-1.7.0.jar
commons-collections-3.1.jar
commons-jelly-20050813.225330.jar
commons-jelly-tags-define-1.0.jar
commons-jelly-tags-jsl-1.0.jar
commons-jelly-tags-xml-20050823.222913.jar
commons-jexl-1.0.jar
commons-logging-1.0.4.jar
dom4j-1.6.jar
generama-1.2.1-SNAPSHOT.jar
jaxen-1.1-beta-4.jar
nanocontainer-1.0-beta-3.jar
nanocontainer-ant-1.0-beta-3.jar
picocontainer-1.0.jar
qdox-1.6-SNAPSHOT.jar
saxpath-1.0-FCS.jar
velocity-1.4.jar
xdoclet-2.0.3.jar
xdoclet-plugin-hibernate-1.0.2.jar

4.写ant脚本

<target name="hibernatedoclet"
depends="init, compile"
description="Generate Persistence and form classes">
<taskdef
name="xdoclet"
classname="org.xdoclet.ant.XDocletTask"
classpathref="class.path"
/>
<xdoclet>
<!-- defines the file handled by xdoclet2 -->
<fileset dir="${src.java.dir}">
<include name="**/model/*.java"/>
</fileset>
<!-- defines the processing of a plugin -->
<component
classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
destdir="${hbm.dir}"
version="3.0"
/>
</xdoclet>
</target>

<?xml version="1.0"?>
<project name="xpost" default="init">
    <property name="src.java.dir" value="src"/>

    <property name="build.dir" value="bin"/>
  

    <property name="xdoclet.lib.dir" value="lib"/>
 

    <path id="xdoclet.class.path">
        <fileset dir="${xdoclet.lib.dir}">
            <include name="**/*.jar"/>
        </fileset>
    </path>


    <target name="init">
        <mkdir dir="${build.dir}"/>
    </target>

    <target name="hibernatedoclet"
            depends="removehbm"
            description="Generate Persistence and form classes">

        <taskdef
                name="xdoclet"
                classname="org.xdoclet.ant.XDocletTask"
                classpathref="xdoclet.class.path"/>
        <xdoclet>
            <!-- defines the file handled by xdoclet2 -->
            <fileset dir="${src.java.dir}">
                <include name="**/*.java"/>
            </fileset>
            <!-- defines the processing of a plugin -->
            <component
                    classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
                    destdir="${src.java.dir}"
                    version="3.0"/>
        </xdoclet>
    </target>

 

</project>
5.几个重要的网址
XDoclet标签说明:
http://xdoclet.codehaus.org/HibernateTags#HibernateTags-hibernate.set
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值