天生我才

          常用鏈接

          統計

          最新評論

          如何使用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 天生我才 閱讀(413) 評論(0)  編輯  收藏 所屬分類: J2EE


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


          網站導航:
           
          主站蜘蛛池模板: 射阳县| 饶平县| 白银市| 金平| 皮山县| 东城区| 丰镇市| 柘荣县| 准格尔旗| 多伦县| 太康县| 八宿县| 大丰市| 闵行区| 枝江市| 新野县| 高要市| 古蔺县| 楚雄市| 堆龙德庆县| 游戏| 宜州市| 东安县| 太仓市| 迁安市| 丘北县| 固始县| 融水| 西充县| 伊春市| 安西县| 宣恩县| 西青区| 东莞市| 延庆县| 衡山县| 金堂县| 白沙| 文水县| 桂东县| 仁寿县|