CTB

 

一对一关系配置

<hibernate-mapping package="com.wepull.hibernate.pojo">
 <class name="Card" table="tbl_card">
  <id name="cardId" column="pk_card_id">
   <generator class="native"/>
  </id>
  
  <property name="cardNo" column="card_no"/>
  
  <!-- 需要维护关系的属性,就不是普通属性 -->
  <!-- Person和Card沟通的桥梁是外键fk_card_id -->
  <one-to-one name="person" property-ref="card"/>
  
  <!-- property-ref="card":通过Person的外键pk_card_id,可以得到pk_person_id -->
 </class>
</hibernate-mapping>



<hibernate-mapping package="com.wepull.hibernate.pojo">
 <class name="Person" table="tbl_person">
  <id name="personId" column="pk_person_id">
   <generator class="native"/>
  </id>
  
  <property name="personName" column="person_name"/>
  
  <!-- 唯一外键约束 -->
  <!-- 此一对一属于多对一的特例 -->
  <!-- 先假设多个人共用一张卡,再给fk_card_id添加唯一约束,就变成了一对一关系 -->
  <many-to-one name="card" column="fk_card_id" unique="true" cascade="all"/>
 </class>
</hibernate-mapping>

posted on 2012-06-27 15:55 千面独行客 阅读(137) 评论(1)  编辑  收藏

评论

# re: 一对一关系配置 2012-06-27 16:10 巧克力

大姐,是不是从我的笔记里抠出来的呀?嘿嘿~  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

文章档案

搜索

最新评论

  • 1. re: 我多想告诉你
  • 煽情……
  • -- _小丸子
  • 2. re: 我多想告诉你
  • 面对爱情的男人都是情圣,文笔自然也有所提高。小样,煽情了吧 /偷笑……
  • -- _小丸子
  • 3. re: 我多想告诉你
  • 到底是什么事儿触发了你如此之深的感受啊?前提是这是你写的,嘿嘿~
  • --巧克力
  • 4. re: 走过自己
  • 刚开始看,呵呵几个错别字,看了之后有点儿小沉重,才发现大姐原是个心思很细腻的男生,文笔还可以哟,嘿嘿~
  • --巧克力
  • 5. re: 无题
  • 我觉得自恃清高没啥不好的,呵呵~
  • --巧克力

阅读排行榜

评论排行榜