甜咖啡

          我的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)

          我參與的團隊

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 珲春市| 韶关市| 惠东县| 定安县| 广州市| 高安市| 太湖县| 兴业县| 孙吴县| 惠安县| 庐江县| 浦北县| 上林县| 德兴市| 新巴尔虎右旗| 中西区| 安平县| 岫岩| 沙田区| 蓝山县| 玉门市| 南岸区| 福清市| 天气| 揭西县| 喀喇沁旗| 苍南县| 永靖县| 濉溪县| 铜川市| 友谊县| 尉犁县| 宿松县| 惠州市| 雷波县| 富蕴县| 贺兰县| 靖边县| 泸水县| 攀枝花市| 白银市|