新聞中心
一:Hibernate實(shí)體對(duì)象的加載

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)洛南免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
比如說(shuō):用戶和訂單的關(guān)系是一對(duì)多,雖然它們有關(guān)聯(lián),但是默認(rèn)是延遲加載Lazy=“true”,最終得到的是代理對(duì)象,如果要訪問(wèn)代理對(duì)象的屬性的話,則會(huì)拋出異常,
解決方法:leftjoinfetch迫切抓取連接
selectufromUseruleftjoinfetchOrdero;
二:Hibernate普通屬性
默認(rèn)是:lazy=“false”
如果要改為延遲方法較麻煩
三:Hibernate集合對(duì)象
setlistmap默認(rèn)Lazy=“true”
1:List
- Java代碼
- <listnamelistname="diarys"table="petDiary"cascade="all"inverse="true">
- <keycolumnkeycolumn="petId">
- <indexcolumnindexcolumn="listindex">
- <one-to-manyclassone-to-manyclass="com.lovo.po.PetDiary"/>
- <listnamelistname="diarys"table="petDiary"cascade="all"inverse="true">
- <keycolumnkeycolumn="petId">
- <indexcolumnindexcolumn="listindex">
- <one-to-manyclassone-to-manyclass="com.lovo.po.PetDiary"/>
2:set
- Java代碼
- <setnamesetname="orders"
- table="t_order"
- cascade="all"
- inverse="true"
- lazy="true"
- >
- <keycolumnkeycolumn="fk_customer_id">
- <one-to-manyclassone-to-manyclass="Order"/>
- <setnamesetname="orders"
- table="t_order"
- cascade="all"
- inverse="true"
- lazy="true"
- >
- <keycolumnkeycolumn="fk_customer_id">
- <one-to-manyclassone-to-manyclass="Order"/>
3:map
- Java代碼
- privateMapschool=newHashMap();
- publicMapgetSchool(){
- returnschool;
- }
- publicvoidsetSchool(Mapschool){
- this.school=school;
- }
- privateMapschool=newHashMap();
- publicMapgetSchool(){
- returnschool;
- }
- publicvoidsetSchool(Mapschool){
- this.school=school;
- }
- Xml代碼
- <mapnamemapname="school"table="schools">
- <keycolumnkeycolumn="pid"not-null="true"/>
- <map-keytypemap-keytype="string"column="indet"/>
- <elementtypeelementtype="float"column="score"/>
- privateMapschool=newHashMap();
- publicMapgetSchool(){
- returnschool;
- }
- publicvoidsetSchool(Mapschool){
- this.school=school;
- }
- privateMapschool=newHashMap();
- publicMapgetSchool(){
- returnschool;
- }
- publicvoidsetSchool(Mapschool){
- this.school=school;
- }
- Xml代碼
- <mapnamemapname="school"table="schools">
- <keycolumnkeycolumn="pid"not-null="true"/>
- <map-keytypemap-keytype="string"column="indet"/>
- <elementtypeelementtype="float"column="score"/>
key子元素用于映射外鍵列,而map-key子元素則用于映射Map集合的Key。
當(dāng)前文章:淺談Hibernate中加載的三種類型
URL鏈接:http://www.dlmjj.cn/article/cocssdc.html


咨詢
建站咨詢
