多對多關(guān)聯(lián)在關(guān)系數(shù)據(jù)庫中不能直接實(shí)現(xiàn),還必須依賴一張連接表保存這種關(guān)聯(lián)關(guān)系
訂單表:orders 商品表:items 連接表:selecteditems
orders:
id int(4) <pk>
orderno varchar(20)
moeny decimal(10,2)
items:
id int(4) <pk>
itemno varchar(20)
itemname varchar(60)
selecteditems:
orderid int(4) <pk,fk1>
itemid int(4) <pk,fk2>
2.pojo類
public class Orders implements Serilizable}
private Integer id;
private String orderno;
private Double moeny;
private Set items=new HashSet();
public Orders(){
}
}
public class Items implements Serilizable{
private Integer id;
private String itemno;
private String itemname;
private Set orders=new HashSet();
public Items(){
}
}
3.hbm.xml
<hibernate-mapping package="com.lhb.vo">
<class name="Orders" table="orders">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>
<property name="orderno" column="orderno" type="string"/>
<property name="moeny" column="moeny" type="double"/>
<set name="items" cascade="save-update" lazy="true"
<!--指定連接表的名字-->
table="selecteditems">
<key column="order_id"/>
<many-to-many class="com.lhb.vo.Items"
<!--指定參照items表的外鍵名字-->
column="item_id"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.lhb.vo">
<class name="Items" table="orders">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>
<property name="itemno" column="itemno" type="string"/>
<property name="itemname" column="itemname" type="double"/>
<set name="items" cascade="save-update" lazy="true" inverse="true"
<!--指定連接表的名字-->
table="selecteditems">
<key column="items_id"/>
<many-to-many class="com.lhb.vo.Orders"
<!--指定參照items表的外鍵名字-->
column="orders_id"/>
</set>
</class>
</hibernate-mapping>
只有注冊用戶登錄后才能發(fā)表評論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
|
||
相關(guān)文章:
|
||
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
27 | 28 | 29 | 30 | 1 | 2 | 3 | |||
4 | 5 | 6 | 7 | 8 | 9 | 10 | |||
11 | 12 | 13 | 14 | 15 | 16 | 17 | |||
18 | 19 | 20 | 21 | 22 | 23 | 24 | |||
25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
1 | 2 | 3 | 4 | 5 | 6 | 7 |
長春語林科技?xì)g迎您!
常用鏈接
留言簿(6)
隨筆分類
- ajax(2)
- android(5)
- css(2)
- db2(2)
- docker(10)
- flex(22)
- hibernate(16)
- html5(9)
- java(12)
- java8(8)
- jquery(4)
- js(30)
- jsp(2)
- jstl(3)
- linux(14)
- mongodb(1)
- mui(1)
- mysql(14)
- oracle(3)
- spring(8)
- sqlserver(4)
- struts(9)
- struts2(13)
- tomcat(6)
- UML(1)
- util(50)
- vue(1)
- weblogic(1)
隨筆檔案
- 2020年4月 (1)
- 2020年3月 (1)
- 2020年2月 (2)
- 2019年10月 (2)
- 2019年9月 (1)
- 2019年7月 (1)
- 2019年4月 (1)
- 2019年1月 (1)
- 2018年12月 (2)
- 2018年8月 (1)
- 2018年6月 (3)
- 2018年5月 (9)
- 2018年3月 (9)
- 2017年12月 (1)
- 2017年10月 (1)
- 2017年7月 (1)
- 2017年6月 (1)
- 2017年5月 (1)
- 2017年3月 (3)
- 2017年2月 (2)
- 2017年1月 (1)
- 2016年12月 (1)
- 2016年11月 (1)
- 2016年9月 (1)
- 2016年4月 (3)
- 2016年3月 (2)
- 2015年8月 (5)
- 2015年3月 (1)
- 2014年8月 (1)
- 2012年11月 (1)
- 2012年5月 (2)
- 2012年4月 (5)
- 2011年12月 (1)
- 2011年10月 (3)
- 2011年9月 (2)
- 2011年8月 (10)
- 2011年7月 (3)
- 2011年6月 (4)
- 2011年5月 (2)
- 2011年4月 (3)
- 2011年3月 (12)
- 2011年1月 (2)
- 2010年12月 (1)
- 2010年9月 (2)
- 2010年8月 (4)
- 2010年6月 (1)
- 2010年4月 (1)
- 2010年3月 (1)
- 2009年11月 (1)
- 2009年9月 (2)
- 2009年8月 (1)
- 2009年7月 (2)
- 2009年6月 (1)
- 2009年5月 (3)
- 2009年4月 (8)
- 2009年3月 (5)
- 2009年2月 (4)
- 2009年1月 (2)
- 2008年12月 (10)
- 2008年11月 (2)
- 2008年9月 (10)
- 2008年8月 (12)
- 2008年7月 (12)
- 2008年6月 (3)
- 2008年5月 (53)
文章分類
文章檔案
相冊
收藏夾
搜索
最新評論

- 1.?re: js 操作文件[未登錄]
- 00
- --00
- 2.?re: s:bean.jsp
- fdfdsa
- --dfasdf
- 3.?re: hibernate 常用標(biāo)識生成器
- 藝達(dá)廣告歡迎您
- --藝達(dá)廣告
- 4.?re: linux mod_jk.so 下載[未登錄]
- 3Q!
- --me
- 5.?re: weblogic參數(shù)設(shè)置[未登錄]
- 垃圾
- --xx