java學(xué)習(xí)

          java學(xué)習(xí)

           

          hibernate中實(shí)體類中有其他普通類的引用,普通類的屬性在數(shù)據(jù)庫中是實(shí)體類的一個(gè)字段

          例如:
          普通類:

          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;
           }
          }

          實(shí)體類:

          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>
          在數(shù)據(jù)庫中在t_user表中含有Contact類的屬性字段

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


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 德令哈市| 剑阁县| 安阳市| 西安市| 阿尔山市| 武宁县| 介休市| 德昌县| 山阴县| 宿州市| 鄢陵县| 峨眉山市| 于田县| 淮安市| 宝清县| 连云港市| 北海市| 巴东县| 铅山县| 浑源县| 怀安县| 佛教| 勐海县| 临桂县| 固阳县| 静宁县| 高密市| 托克逊县| 六盘水市| 远安县| 无极县| 自贡市| 财经| 龙门县| 四平市| 玉山县| 玉林市| 资阳市| 专栏| 大化| 隆化县|