甜咖啡

          我的IT空間

          hibernate_組件映射_annotation方式

          package org.hibernate.tutorial.domain;

          import javax.persistence.Embedded;
          import javax.persistence.Entity;
          import javax.persistence.GeneratedValue;
          import javax.persistence.Id;

          @Entity
          public class Husband {
              private int id;
              private String name;
              private Wife wife;

              @Id
              @GeneratedValue
              public int getId() {
                  return id;
              }

              public String getName() {
                  return name;
              }

              @Embedded
              public Wife getWife() {
                  return wife;
              }

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

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

              public void setWife(Wife wife) {
                  this.wife = wife;
              }

          }

          package org.hibernate.tutorial.domain;

          import javax.persistence.Column;


          public class Wife {
              private int id;
              private String name;
              
              @Column(name="wife_id") //注意映射的組件內屬性名不應相同
              public int getId() {
                  return id;
              }
              @Column(name="wife_name")
              public String getName() {
                  return name;
              }
              public void setId(int id) {
                  this.id = id;
              }
              public void setName(String name) {
                  this.name = name;
              }

          }

          package org.hibernate.tutorial.test;

          import org.hibernate.cfg.AnnotationConfiguration;
          import org.hibernate.tool.hbm2ddl.SchemaExport;
          import org.junit.Test;

          /**
           * 測試
           * @author MyPC
           *
           */
          public class TestHusband {
              @Test
              public void testHusband()
              {
                  new SchemaExport(new AnnotationConfiguration().configure()).create(false, true);
              }
          }

          posted on 2011-03-26 23:37 甜咖啡 閱讀(407) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          <2011年3月>
          272812345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          統計

          常用鏈接

          留言簿(1)

          我參與的團隊

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 门头沟区| 温泉县| 松江区| 景洪市| 丁青县| 贞丰县| 海伦市| 青海省| 溧阳市| 溧水县| 郧西县| 石门县| 山东省| 连云港市| 娱乐| 名山县| 中江县| 宜州市| 南部县| 新闻| 金昌市| 托里县| 鹤山市| 合江县| 鹤岗市| 阳朔县| 上犹县| 宁晋县| 泌阳县| 柯坪县| 苏尼特右旗| 霍山县| 平罗县| 禄劝| 永定县| 越西县| 沙坪坝区| 张掖市| 昭苏县| 江达县| 岳阳市|