天生我才

          常用鏈接

          統計

          最新評論

          如何使用XDoclet?

          下面舉例說明(from http://forum.javaeye.com/viewtopic.php?t=2991
          package com.javamodel.hibernate;

          import java.util.HashSet;
          import java.util.Set;

          /**
          * @hibernate.class
          *      table="author"
          *      dynamic-update="true"
          *      dynamic-insert="true"
          *      這個類對應的表是author
          */


          public class Author{
                 
                  private String id ;
                  private String alias = null;
                  private Person person = null;
                  private Set publications = new HashSet();
                  private Set works = new HashSet();
                 
                  /**
                  * @hibernate.id
                  *  unsaved-value="null" generator-class="foreign"
                  *  定義外鍵
                  * @hibernate.generator-param
                  *  name="property" value="person"
                  *  對應的Author對應的屬性
                  */

                  public String getId() {
                          return id;
                  }

                  public void setId(String i) {
                          id = i;
                  }
                 
                  /**
                  * @hibernate.property
                  *  length="20"
                  *  聲明表中對應的字段 
                  */

                  public String getAlias() {
                          return alias;
                  }

                  public void setAlias(String string) {
                          alias = string;
                  }
                 
                  /**
                  * @hibernate.one-to-one
                  *  cascade="all" constrained="true"
                  * 在Author與Person之間,聲明one-to-one的關聯關系
                  */

                  public Person getPerson() {
                          return person;
                  }

                  public void setPerson(Person person) {
                          this.person = person;
                  }

                  /**
                   * @hibernate.set
                  *  lazy="true" inverse="true" cascade="all"
                  * 定義Hibernate <set> collection
                  * @hibernate.collection-key
                  *  column="authorid"
                  * 對應表中的字段
                  * @hibernate.collection-one-to-many
                  *  class="com.javamodel.hibernate.Publication"
                  * 在Author與Publication之間,聲明one-to-many的關聯關系
                  */

                  public Set getPublications() {
                          return publications;
                  }

                  public void setPublications(Set set) {
                          publications = set;
                  }

                  /**
                  * @hibernate.set
                  *  lazy="true"
                  *  table="author_work"
                  * @hibernate.collection-key
                  *  column="author_id"
                  * @hibernate.collection-many-to-many
                  *  column="work_id"
                  *  class="com.javamodel.hibernate.Work"
                  */

                  public Set getWorks() {
                          return works;
                  }

                  public void setWorks(Set set) {
                          works = set;
                  }

          }


          感覺用起來還是比較麻煩,還是根據數據庫表自動生成來得方便。

          posted on 2005-09-20 20:50 天生我才 閱讀(417) 評論(0)  編輯  收藏 所屬分類: J2EE


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 永泰县| 鲜城| 崇文区| 盘山县| 天镇县| 莎车县| 古丈县| 改则县| 英山县| 临澧县| 河东区| 承德市| 博野县| 锡林浩特市| 佛学| 正定县| 陇川县| 蓬溪县| 星子县| 包头市| 施甸县| 濮阳县| 诸城市| 呼玛县| 赫章县| 罗江县| 宣武区| 汉川市| 连南| 萝北县| 长沙县| 正蓝旗| 紫金县| 东乌珠穆沁旗| 台湾省| 林西县| 五原县| 郧西县| 高青县| 莆田市| 宁海县|