锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
鍋囪鏈変袱涓〃錛孭hotos(涓錛壜?---聽 picture(澶氾級Photo鍖呭惈picture闆嗗悎
緇撹1錛?HQL浠g爜 > fetch錛堥厤緗級 > lazy 錛堥厤緗級
緇撹2錛?榛樿 lazy="true"
緇撹3錛?fetch 鍜?lazy 涓昏鏄敤鏉ョ駭鑱旀煡璇㈢殑錛屄犅?鑰?cascade 鍜?inverse 涓昏鏄敤鏉ョ駭鑱旀彃鍏ュ拰淇敼鐨?br />緇撹4錛?濡傛灉浣犳槸鐢╯pring鏉ュ府浣犵鐞嗕綘鐨剆ession, 騫朵笖鏄嚜鍔ㄦ彁浜わ紝寤惰繜鍔犺澆灝辯瓑浜庢病鍔犺澆~_~(褰撶劧
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 闄ら潪浣犳墜鍔ㄩ噸鏂版墦寮session鐒跺悗鎵嬪姩Hibernate.initialize(set);鐒跺悗鍏抽棴session.
緇撹5:聽聽聽聽聽cascade涓昏鏄畝鍖栦簡鍦ㄤ唬鐮佷腑鐨勭駭鑱旀洿鏂板拰鍒犻櫎銆?br />j緇撹6錛氳佺埜鍙互鏈夊涓瀛愶紝涓涓瀛愪笉鑳芥湁澶氫釜鑰佺埜錛岃屼笖鑰佺埜璇寸殑綆? 瀛╁瓙鍥寸潃鑰佺埜杞?br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽鎵浠hotos鑰佺埜瑕佹湁鏉冨姏鎵浠?cascade聽榪欎釜鍏抽敭瀛愰兘鏄佺粰鑰佺埜鐨勶紝聽涔熷氨鏄駭鑱旀洿鏂幫紝
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 鑰佺埜鏀瑰浜嗭紝鍎垮瓙涔熷緱璺熺潃鏀癸紝鍛靛懙銆傗滀笉鐒訛紝灝辨病鏈夐浂鑺遍挶鍜濄?br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 鑰孭icture鍎垮瓙鏁翠綋鎸ㄩ獋錛屼絾鏄繕鏄緇存姢鐖跺瓙涔嬮棿鑹ソ鐨勫叧緋伙紝瀵硅佺埜鐧句緷鐧鵑『錛屾墍
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 浠ヨ佺埜灝辮錛屽効瀛愶紝鈥滃叧緋伙紝鐢變綘鏉ョ淮鎶わ紙inverse="true")聽錛屼笉鐒跺氨涓嶇粰闆惰姳閽便傚懙銆傗濄?br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <set name="pictures" inverse="true" cascade="all">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <key>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <column name="photosid" not-null="true" />
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </key>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <one-to-many class="girl.domain.Picture" />
聽聽聽聽聽聽聽聽 聽聽聽 </set>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
嫻嬭瘯浠g爜錛?br />
聽聽聽Photos p = ps.getById(1);
聽聽Set<Picture> set = p.getPictures();
聽聽for(Picture pic : set){
聽 聽聽聽System.out.println(pic.getId());
聽聽}
聽 閰嶇疆鏂囦歡鐨勪竴閮ㄥ垎錛?br />聽聽聽聽聽聽 <set name="pictures" inverse="true" cascade="all" >
聽聽聽聽聽聽聽聽聽聽聽 <key>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <column name="photosid" not-null="true" />
聽聽聽聽聽聽聽聽聽聽聽 </key>
聽聽聽聽聽聽聽聽聽聽聽 <one-to-many class="girl.domain.Picture" />
聽聽聽聽聽聽聽 </set>
嫻嬭瘯榪囩▼浼氬閰嶇疆鏂囦歡涓嶆柇淇敼錛氬茍涓斾粠鏉ヤ笉鏇炬墜鍔ㄩ噸鏂版墦寮session
嫻嬭瘯緇撴瀯錛?br />
褰撻厤緗潯浠朵負 lazy=true 涓鍙ユ煡璇?嫻嬭瘯浠g爜涓病鏈夎皟鐢╣etPicture() 聽姝e父
Hibernate: select photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where photos0_.id=?
lazy=true 涓鍙ユ煡璇?鏈塯etPicture()
Hibernate: select photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where photos0_.id=?
lazy=true 涓鍙ユ煡璇⒙?鏈塯etPicture() 騫朵笖璁塊棶浜嗛噷闈㈢殑鍏冩暟Picture 涓旀湁寮傚父鎶涘嚭
Hibernate: select photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where photos0_.id=?
lazy="false" 涓ゅ彞鏌ヨ聽 鑲畾娌¢棶棰橈紝鍥犱負鍏ㄩ儴鏁版嵁閮戒釜鏌ヤ簡鍑烘潵 鎵浠ユ庝箞璋冪敤閮芥甯?br />Hibernate: select photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where photos0_.id=?
Hibernate: select pictures0_.photosid as photosid1_, pictures0_.id as id1_, pictures0_.id as id2_0_, pictures0_.photosid as photosid2_0_, pictures0_.name as name2_0_, pictures0_.clicked as clicked2_0_, pictures0_.uploaddate as uploaddate2_0_, pictures0_.size as size2_0_, pictures0_.description as descript7_2_0_, pictures0_.uri as uri2_0_ from super.picture pictures0_ where pictures0_.photosid=?
fetch="join"聽 涓鍙ユ煡璇⒙?鏁堟灉 錛濓紳 lazy="false" 鍛靛懙錛屽摢涓晥鐜囬珮錛屾垜灝變笉鐭ラ亾浜嗐傘傘傘傘傘傘傘傘傘傘?br />Hibernate: select photos0_.id as id0_1_, photos0_.userid as userid0_1_, photos0_.typeid as typeid0_1_, photos0_.name as name0_1_, photos0_.createtime as createtime0_1_, photos0_.description as descript6_0_1_, photos0_.faceid as faceid0_1_, photos0_.uri as uri0_1_, pictures1_.photosid as photosid3_, pictures1_.id as id3_, pictures1_.id as id2_0_, pictures1_.photosid as photosid2_0_, pictures1_.name as name2_0_, pictures1_.clicked as clicked2_0_, pictures1_.uploaddate as uploaddate2_0_, pictures1_.size as size2_0_, pictures1_.description as descript7_2_0_, pictures1_.uri as uri2_0_ from super.photos photos0_ left outer join super.picture pictures1_ on photos0_.id=pictures1_.photosid where photos0_.id=?
涓嶅姞fetch錛?join" 涓鍙ユ煡璇⒙?娌℃湁getPicture() 姝e父
Hibernate: select photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where photos0_.id=?
涓嶅姞fetch錛?join" 涓鍙ユ煡璇⒙?鏈塯etPicture() 姝e父
Hibernate: select photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where photos0_.id=?
涓嶅姞fetch錛?join" 涓鍙ユ煡璇?鏈塯etPicture() 騫朵笖璁塊棶閲岄潰鐨勫厓绱燩icture鐨処D 鏈夊紓甯告姏鍑?br />Hibernate: select photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where photos0_.id=?
鏉ヤ釜涓ゅ叺浜ゆ垬 fetch="join" lazy="true"聽 鍛靛懙 緇撴灉錛屼竴鍙ユ煡璇紝 緇撴瀯姝e父 鎵浠ュ氨褰搇azy涓嶅瓨鍦ㄥソ浜嗐?鐪嬫潵fetch 鏄佸ぇ銆傘併併併併併併併併併併併併?br />Hibernate: select photos0_.id as id0_1_, photos0_.userid as userid0_1_, photos0_.typeid as typeid0_1_, photos0_.name as name0_1_, photos0_.createtime as createtime0_1_, photos0_.description as descript6_0_1_, photos0_.faceid as faceid0_1_, photos0_.uri as uri0_1_, pictures1_.photosid as photosid3_, pictures1_.id as id3_, pictures1_.id as id2_0_, pictures1_.photosid as photosid2_0_, pictures1_.name as name2_0_, pictures1_.clicked as clicked2_0_, pictures1_.uploaddate as uploaddate2_0_, pictures1_.size as size2_0_, pictures1_.description as descript7_2_0_, pictures1_.uri as uri2_0_ from super.photos photos0_ left outer join super.picture pictures1_ on photos0_.id=pictures1_.photosid where photos0_.id=?