posts - 12,  comments - 2,  trackbacks - 0

          ?

          一對(duì)一的關(guān)系 如(CrmCustomer 和CrmReasearch,CrmIntendInfo是一對(duì)一的關(guān)系
          ??????????????????????? 分別是客戶(hù),客戶(hù)調(diào)查和客戶(hù)意向調(diào)查

          public ? class ?CrmCustomer? implements ?java.io.Serializable {

          ???????
          private ?CrmCustResearch?crmCustResearch;
          ????
          private ?CrmIntendInfo?crmIntendInfo;

          ???????????@OneToOne(cascade?
          = ? {} ,?fetch? = ?FetchType.LAZY)
          ????@PrimaryKeyJoinColumn
          ????
          public ?CrmCustResearch?getCrmCustResearch()? {
          ????????
          return ? this .crmCustResearch;
          ????}


          ????
          public ? void ?setCrmCustResearch(CrmCustResearch?crmCustResearch)? {
          ????????
          this .crmCustResearch? = ?crmCustResearch;
          ????}

          ??????@OneToOne(cascade?
          = ? {} ,?fetch? = ?FetchType.LAZY)
          ????@PrimaryKeyJoinColumn
          ????
          public ?CrmIntendInfo?getCrmIntendInfo()? {
          ????????
          return ? this .crmIntendInfo;
          ????}


          ????
          public ? void ?setCrmIntendInfo(CrmIntendInfo?crmIntendInfo)? {
          ????????
          this .crmIntendInfo? = ?crmIntendInfo;
          ????}



          ?}



          在CrmResearch 和CrmIntendInfo 進(jìn)行相應(yīng)的設(shè)置
          public?class?CrmCustResearch?implements?java.io.Serializable?{
          ???
          private?long?custId;
          ?????
          public?CrmCustResearch(long?custId,?String?epId)?{
          ????????
          this.custId?=?custId;
          ????????
          this.epId?=?epId;
          ????}

          ????????????}


          在數(shù)據(jù)庫(kù)里面custId 設(shè)置為外鍵 指向CrmCustomer的custId

          另外一種一對(duì)一關(guān)系的類(lèi)型,不是通過(guò)相同的鍵來(lái)連接 ,而是通過(guò)直接設(shè)置一對(duì)一關(guān)系來(lái)連接?
          public???class??CrmCommInfoType??implements??java.io.Serializable?{?
          ???????
          //?一對(duì)一關(guān)系?
          ????? ?private long commTypeId;
          ?????private??CrmCommonInfo?crmCommonInfo;
          ???????@OneToOne(cascade??
          =??{},?fetch??=??FetchType.LAZY,?mappedBy??=???"?crmCommInfoType?"?,optional?=?true?)
          ??????
          //?mappedBy=crmCommInfoType,是和這個(gè)表一對(duì)一的CrmCommInfo?里面的關(guān)聯(lián)字段?
          ?????public??CrmCommonInfo?getCrmCommonInfo()?{
          ?????????
          return???this?.crmCommonInfo;
          ????}
          ??????
          ???}????

          public?class?CrmCommonInfo?implements?java.io.Serializable?{

          ???????
          private?long?crmCommonInfoId;
          ???????
          private?CrmCommInfoType?crmCommInfoType;//mappedby 的crmCommInfoType
          ???????????
          ????@OneToOne(cascade?
          =?{},?fetch?=?FetchType.LAZY)
          ????@JoinColumn(name?
          =?"COMM_TYPE_ID",referencedColumnName?=?"COMM_TYPE_ID",unique?=?true)//要連接的欄的名字,數(shù)據(jù)庫(kù)里面的字段 ?
          ????
          public?CrmCommInfoType?getCrmCommInfoType()?{
          ????????
          return?this.crmCommInfoType;
          ????}

          ????
          public?void?setCrmCommInfoType(CrmCommInfoType?crmCommInfoType)?{
          ????????
          this.crmCommInfoType?=?crmCommInfoType;
          ????}

          ?}

          還要在數(shù)據(jù)庫(kù)里面設(shè)置外間約束(如在MySql 下面要設(shè)置的Sql如下)
          ALTER?TABLE?CRM_COMMON_INFO?CONSTRAINT?FKF8882C3D003D0B1?FOREIGH?KEY(COMM_TYPE_ID)?REFERENCES?CRM_COMM_INFO_TYPE(COMM_TYPE_ID)

          posted on 2006-09-23 11:11 doodoosun 閱讀(209) 評(píng)論(0)  編輯  收藏

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


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

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(1)

          隨筆分類(lèi)(6)

          隨筆檔案(11)

          文章分類(lèi)(30)

          文章檔案(34)

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 西林县| 丹阳市| 蒙山县| 东方市| 林州市| 恩平市| 垫江县| 舒城县| 昔阳县| 天峨县| 敦化市| 隆昌县| 大关县| 大安市| 万全县| 当涂县| 连城县| 涡阳县| 玉龙| 正镶白旗| 丰县| 正阳县| 平昌县| 西昌市| 舞钢市| 大庆市| 永昌县| 吴川市| 岢岚县| 天门市| 博乐市| 陆川县| 中西区| 岑溪市| 宕昌县| 时尚| 阿拉善盟| 松阳县| 东明县| 米易县| 师宗县|