java學習

          java學習

           

          hibernate中實體類中有其他普通類的引用,普通類的屬性在數據庫中是實體類的一個字段

          例如:
          普通類:

          public class Contact {
           
           private String email;
           
           private String address;
           
           private String zipCode;
           
           private String contactTel;

           public String getEmail() {
            return email;
           }

           public void setEmail(String email) {
            this.email = email;
           }

           public String getAddress() {
            return address;
           }

           public void setAddress(String address) {
            this.address = address;
           }

           public String getZipCode() {
            return zipCode;
           }

           public void setZipCode(String zipCode) {
            this.zipCode = zipCode;
           }

           public String getContactTel() {
            return contactTel;
           }

           public void setContactTel(String contactTel) {
            this.contactTel = contactTel;
           }
          }

          實體類:

          public class User {
           
           private int id;
           
           private String name;
           
           private Contact contact;
           
           public int getId() {
            return id;
           }

           public void setId(int id) {
            this.id = id;
           }

           public String getName() {
            return name;
           }

           public void setName(String name) {
            this.name = name;
           }

           public Contact getContact() {
            return contact;
           }

           public void setContact(Contact contact) {
            this.contact = contact;
           }
           
          }

          User.hbm.xml文件:
          <hibernate-mapping>
           <class name="User" table="t_user">
            <id name="id">
             <generator class="native"/>
            </id>
            <property name="name"/>
            <component name="contact">
             <property name="email"/>
             <property name="address"/>
             <property name="zipCode"/>
             <property name="contactTel"/>
            </component>
           </class>
          </hibernate-mapping>
          在數據庫中在t_user表中含有Contact類的屬性字段

          posted on 2013-05-06 22:10 楊軍威 閱讀(550) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 呼图壁县| 余姚市| 桐庐县| 新宾| 托里县| 吴桥县| 彰化市| 天全县| 明溪县| 合水县| 南乐县| 漠河县| 江阴市| 青神县| 依兰县| 咸宁市| 灵山县| 洛扎县| 宣威市| 石家庄市| 栖霞市| 铅山县| 炎陵县| 仙桃市| 富锦市| 大庆市| 新营市| 尼玛县| 札达县| 天门市| 新河县| 措美县| 铜陵市| 民和| 保康县| 称多县| 宝丰县| 天镇县| 东阿县| 岑溪市| 巫溪县|