天生我才

          常用鏈接

          統計

          最新評論

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


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


          網站導航:
           
          主站蜘蛛池模板: 临漳县| 静安区| 监利县| 浮梁县| 邓州市| 科技| 安仁县| 阿城市| 平武县| 承德县| 宁津县| 修文县| 怀来县| 昆山市| 莲花县| 通城县| 安岳县| 深泽县| 专栏| 廊坊市| 临海市| 防城港市| 赫章县| 墨玉县| 囊谦县| 桐梓县| 威海市| 黄浦区| 长武县| 嘉鱼县| 呼伦贝尔市| 合肥市| 澳门| 张家港市| 沾化县| 巩留县| 河间市| 岳阳县| 周至县| 景宁| 明光市|