步骤:
1.下载 XDoclet2,如xdoclet-plugins-1.0.2.zip
下载Hibernate3,如hibernate-3.2.4.sp1.zip
2.写源码如 Event.java
3.建立lib文件夹放入所需的包
4.写ant脚本
或
5.几个重要的网址
XDoclet标签说明:
http://xdoclet.codehaus.org/HibernateTags#HibernateTags-hibernate.set
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; } } |
ant-contrib-1.0b1.jar |
4.写ant脚本
<target name="hibernatedoclet" |
<?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> |
XDoclet标签说明:
http://xdoclet.codehaus.org/HibernateTags#HibernateTags-hibernate.set