欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Hibernate集合映射之List

系統 1638 0

使用List和Map有很多共性,比如說不能再1方設置inverse="true"

不同的是,list可以保留元素的順序,這個使通過一個idx字段來實現的,比如說Team和Student的1對多關系,我們給team加入學生的時候,需要記錄加入的順序,這時候我們可以使用list方式,并在student表中新增加一個idx字段(但在Student實體類中不定義idx屬性)?

數據庫結構:

?

create ? table ?teamList?(id? varchar ( 32 ),teamname? varchar ( 32 ));
create ? table ?studentList?(id? varchar ( 32 ),cardid? varchar ( 32 ),name? varchar ( 32 ),age? int ,description? varchar ( 32 ),?team_id? varchar ( 32 ),idx? int );

?

POJO

?

package ?Collection.List;

import ?java.util.ArrayList;
import ?java.util.List;
import ?java.util.Map;

public ? class ?Team? ... {
???
private ?String?id;
???
private ?String?teamname;
???
private ?List?students = new ?ArrayList();
public ?String?getId()? ... {
????
return ?id;
}

public ? void ?setId(String?id)? ... {
????
this .id? = ?id;
}

public ?String?getTeamname()? ... {
????
return ?teamname;
}

public ? void ?setTeamname(String?teamname)? ... {
????
this .teamname? = ?teamname;
}

public ?List?getStudents()? ... {
????
return ?students;
}

public ? void ?setStudents(List?students)? ... {
????
this .students? = ?students;
}


}




package ?Collection.List;

public ? class ?Student? ... {
??
private ?String?id;
??
private ?String?name;
??
private ?String?description;
??
private ? int ?age;
??
private ?String?cardid;
??
private ?Team?team;
public ?String?getId()? ... {
????
return ?id;
}

public ? void ?setId(String?id)? ... {
????
this .id? = ?id;
}

public ?String?getName()? ... {
????
return ?name;
}

public ? void ?setName(String?name)? ... {
????
this .name? = ?name;
}

public ?String?getDescription()? ... {
????
return ?description;
}

public ? void ?setDescription(String?description)? ... {
????
this .description? = ?description;
}

public ? int ?getAge()? ... {
????
return ?age;
}

public ? void ?setAge( int ?age)? ... {
????
this .age? = ?age;
}

public ?String?getCardid()? ... {
????
return ?cardid;
}

public ? void ?setCardid(String?cardid)? ... {
????
this .cardid? = ?cardid;
}

public ?Team?getTeam()? ... {
????
return ?team;
}

public ? void ?setTeam(Team?team)? ... {
????
this .team? = ?team;
}

}

?

Team.hbm.xml

?

<? xml?version="1.0"?encoding="utf-8" ?>
<! DOCTYPE?hibernate-mapping?PUBLIC?"-//Hibernate/Hibernate?Mapping?DTD?3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<!-- ?
????Mapping?file?autogenerated?by?MyEclipse?-?Hibernate?Tools
-->
< hibernate-mapping >
< class? name ="Collection.List.Team" ?table ="teamList" ? >
????
< id? name ="id" ?unsaved-value ="null" >
??????
< generator? class ="uuid.hex" ></ generator >
????
</ id >
????
< property? name ="teamname" ?type ="string" ?column ="teamname" ></ property >
????
<!-- 由于index需要team來維護,所以,使用list表示1對多時候,不能再1方設置inverse="true" -->
????
< list? name ="students" ?table ="studentList" ?cascade ="all" ? >
??????
< key? column ="team_id" ></ key >
??????
<!-- ?index代表key,element(或one-to-many)代表value -->
??????
<!-- ?這里用cardid作為key,具體的student實例作為value? -->
??????
< index? column ="idx" ?type ="int" ></ index >
??????
< one-to-many? class ="Collection.List.Student" />
????
</ list >
</ class >

</ hibernate-mapping >

?

Student.hbm.xml

?

<? xml?version="1.0"?encoding="utf-8" ?>
<! DOCTYPE?hibernate-mapping?PUBLIC?"-//Hibernate/Hibernate?Mapping?DTD?3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<!-- ?
????Mapping?file?autogenerated?by?MyEclipse?-?Hibernate?Tools
-->
< hibernate-mapping >
< class? name ="Collection.List.Student" ?table ="studentList" ? >
????
< id? name ="id" ?unsaved-value ="null" >
??????
< generator? class ="uuid.hex" ></ generator >
????
</ id >
????
< property? name ="cardid" ?type ="string" ?column ="cardid" ></ property >
????
< property? name ="name" ?type ="string" ?column ="name" ></ property >
????
< property? name ="age" ?type ="int" ?column ="age" ></ property >
????
< property? name ="description" ?type ="string" ?column ="description" ></ property > ?
????
< many-to-one? name ="team" ?
?????????????????column
="team_id"
?????????????????class
="Collection.List.Team" ?
?????????????????cascade
="none" ?
?????????????????fetch
="join" >
????
</ many-to-one >
</ class >

</ hibernate-mapping >

?

Hibernate.cfg.xml

?

<? xml?version='1.0'?encoding='UTF-8' ?>
<! DOCTYPE?hibernate-configuration?PUBLIC
??????????"-//Hibernate/Hibernate?Configuration?DTD?3.0//EN"
??????????"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
>

<!-- ?Generated?by?MyEclipse?Hibernate?Tools.??????????????????? -->
< hibernate-configuration >

< session-factory >
????
< property? name ="connection.username" > root </ property >
????
< property? name ="connection.url" >
????????jdbc:mysql://localhost:3306/schoolproject?characterEncoding=gb2312
&amp; useUnicode=true
????
</ property >
????
< property? name ="dialect" >
????????org.hibernate.dialect.MySQLDialect
????
</ property >
????
< property? name ="myeclipse.connection.profile" > mysql </ property >
????
< property&n

Hibernate集合映射之List


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产精品极品美女自在线看免费一区二区 | 亚洲日韩中文字幕天堂不卡 | 欧美激情 自拍 | 色橹橹欧美在线观看视频高清免费 | 男人午夜免费视频 | 国产一区二区三区乱码 | 亚洲美女亚洲精品久久久久 | 嫩草电影院| 三级三级三级a三级三级 | 亚洲 日本 欧美 中文幕 | 久久精品黄色 | 亚洲第一页在线观看 | 亚洲三级在线 | 成人三级视频 | 欧美久久久网站 | 精品日本三级在线观看视频 | 亚洲日韩欧美综合 | 亚洲日本香蕉 | 国产在线一区二区三区 | 成年男女免费视频 | 精品卡1卡二卡3卡 | 久久99国产精品免费网站 | 精品成人久久久 | 成人毛片国产a | 丁香婷婷六月综合交清 | 亚洲欧美在线免费观看 | 久久精品蜜芽亚洲国产a | 凤囚凰 电视剧 | 日韩18视频在线观看 | a久久久久一级毛片护士免费 | 亚洲国产欧洲综合997久久 | 亚洲精品乱码8久久久久久日本 | 狠狠搞视频 | 久草8| 成人午夜在线观看 | 欧美一区二区三区四区五区 | 欧美视频三区 | 欧美日韩中文在线观看 | 国产精品欧美一区二区在线看 | 5月婷婷6月丁香 | 精品女同一区二区三区免费播放 |