posts - 12,  comments - 2,  trackbacks - 0

          ?

          一對一的關系 如(CrmCustomer 和CrmReasearch,CrmIntendInfo是一對一的關系
          ??????????????????????? 分別是客戶,客戶調查和客戶意向調查

          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 進行相應的設置
          public?class?CrmCustResearch?implements?java.io.Serializable?{
          ???
          private?long?custId;
          ?????
          public?CrmCustResearch(long?custId,?String?epId)?{
          ????????
          this.custId?=?custId;
          ????????
          this.epId?=?epId;
          ????}

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


          在數據庫里面custId 設置為外鍵 指向CrmCustomer的custId

          另外一種一對一關系的類型,不是通過相同的鍵來連接 ,而是通過直接設置一對一關系來連接?
          public???class??CrmCommInfoType??implements??java.io.Serializable?{?
          ???????
          //?一對一關系?
          ????? ?private long commTypeId;
          ?????private??CrmCommonInfo?crmCommonInfo;
          ???????@OneToOne(cascade??
          =??{},?fetch??=??FetchType.LAZY,?mappedBy??=???"?crmCommInfoType?"?,optional?=?true?)
          ??????
          //?mappedBy=crmCommInfoType,是和這個表一對一的CrmCommInfo?里面的關聯字段?
          ?????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)//要連接的欄的名字,數據庫里面的字段 ?
          ????
          public?CrmCommInfoType?getCrmCommInfoType()?{
          ????????
          return?this.crmCommInfoType;
          ????}

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

          ?}

          還要在數據庫里面設置外間約束(如在MySql 下面要設置的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 閱讀(207) 評論(0)  編輯  收藏

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


          網站導航:
           

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(1)

          隨筆分類(6)

          隨筆檔案(11)

          文章分類(30)

          文章檔案(34)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 都安| 鄱阳县| 绩溪县| 泸溪县| 大城县| 乐清市| 安仁县| 海宁市| 周宁县| 长子县| 刚察县| 罗江县| 曲沃县| 咸阳市| 亳州市| 东乡| 龙山县| 隆林| 大石桥市| 南江县| 柳林县| 繁昌县| 丹棱县| 西乡县| 基隆市| 景宁| 七台河市| 安福县| 仁布县| 若羌县| 安新县| 左云县| 乐东| 景泰县| 紫阳县| 丰顺县| 勃利县| 花莲县| 濮阳市| 霍林郭勒市| 东山县|