freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

跟我學(xué)hibernate框架技術(shù)——在容器外實(shí)現(xiàn)“一對(duì)多”的關(guān)聯(lián)-資料下載頁(yè)

2025-10-28 11:01本頁(yè)面

【導(dǎo)讀】滿足“主——外鍵”關(guān)系的設(shè)計(jì)要求。

  

【正文】 ws HibernateException,UnsupportedEncodingException { String selectHQL=from 。 ArrayList acturlReturn=(selectHQL)。 (acturlReturn)。 (()0)。 } @Test public void testGetPersonCats() throws HibernateException, UnsupportedEncodingException { int personId=1234。 Set acturlReturn=(personId)。 (acturlReturn)。 (()0)。 } } 執(zhí)行該測(cè)試用例 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 27/34 頁(yè) 27 體驗(yàn)延遲加載 延遲加載( Fetching strategies,取數(shù)據(jù)的一種策略) Fetching stategies 是指 hibernate 在需要關(guān)聯(lián)數(shù)據(jù)的時(shí)候所采用的取關(guān)聯(lián)數(shù)據(jù)的策略。 延遲加載是在同一個(gè)會(huì)話中實(shí)現(xiàn)的(在同一個(gè) session 中完成) 將前面的 getPersonCats 方法改變?yōu)橄旅娴膬?nèi)容 常規(guī)的 Hibernate 的 DAO 訪問方法的編程形式 public Set getPersonCats(int personId) throws HibernateException { Session session=null。 Transaction tx=null。 allCatsByOnePerson=null。 try { session = ()。 tx= ()。 PersonPO onePerson = (PersonPO) (, new Integer(personId))。 allCatsByOnePerson=()。 ()。 } catch(HibernateException he) { if ( tx!=null ) 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 28/34 頁(yè) 28 { ()。 } throw he。 } finally { ()。 } return allCatsByOnePerson。 } 再執(zhí)行測(cè)試用例 將出現(xiàn)下面的錯(cuò)誤 : failed to lazily initialize a collection of role: , no session or session was closed (:370) (:291) (:241) (:802) 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 29/34 頁(yè) 29 ( 6)為了能夠應(yīng)用延遲加載,則不能關(guān)閉 Session。 public Set getPersonCats(int personId) throws HibernateException{ Session session = ()。 PersonPO onePerson = (PersonPO) (, new Integer(personId))。 allCatsByOnePerson=()。 return allCatsByOnePerson。 } 那如何關(guān)閉 Session?我們總不能不關(guān)閉 Session! 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 30/34 頁(yè) 30 如何解決上面的問題 ( 1)解決的方法之一 public Set getPersonCats(int personId) throws HibernateException{ Session session=null。 Transaction tx=null。 allCatsByOnePerson=null。 try { session = ()。 tx= ()。 PersonPO onePerson = (PersonPO) (, new Integer(personId))。 allCatsByOnePerson=()。 ()。 } catch(HibernateException he){ if ( tx!=null ) { ()。 } throw he。 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 31/34 頁(yè) 31 } finally { ()。 } return allCatsByOnePerson。 } 由于在 版中,默認(rèn)是自動(dòng)應(yīng)用延遲加載。但可以通過下面的配置,取消延遲加載。 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 32/34 頁(yè) 32 該方法的應(yīng)用場(chǎng)合: 如果多端的數(shù)據(jù)比較少。 ( 2)解決的方法之二:應(yīng)用 延遲初始化,但需要 利用 ()方法緩存集合中的數(shù)據(jù)。 set name=cats table=CAT key column=PERSON_ID/ onetomany class=/ /set 如果我們使用了延遲初始化,而在某些時(shí)候我們?nèi)匀恍枰?session 關(guān)閉之后取得相關(guān)實(shí)體,則可以使用 ()來首先載入相關(guān)聯(lián)的實(shí)體,然后再關(guān)閉 Session。 因此,我們的 getPersonCats 方法的代碼應(yīng)該改變?yōu)橄旅娴臓顟B(tài)。 public Set getPersonCats(int personId) throws HibernateException{ allCatsByOnePerson=null。 try{ session = ()。 tx= ()。 Person onePerson = (Person) (, new Integer(personId))。 allCatsByOnePerson=()。 (allCatsByOnePerson)。 ()。 } 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 33/34 頁(yè) 33 catch(HibernateException he) { if ( tx!=null ){ ()。 } throw he。 } finally{ ()。 } return allCatsByOnePerson。 } 再執(zhí)行該測(cè)試用例,將能夠正確進(jìn)行數(shù)據(jù)訪問 楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料 楊教授工作室,版權(quán)所有,盜版必究 , 34/34 頁(yè) 34 在程序里面可以用強(qiáng)制加載的方法 (Object proxy) 方法強(qiáng)制加載這樣就相當(dāng)于動(dòng)態(tài)改變?yōu)?lazy=false。但在使用時(shí)需要注意的一點(diǎn)是:其中的 proxy 是持久對(duì)象的關(guān)聯(lián)對(duì)象屬性,比如 A 實(shí)體,你要把 A 的關(guān)聯(lián)實(shí)體 B 也檢出,則要寫 ()。 總結(jié):上面的兩種解決的方法在應(yīng)用中都存在一定的欠缺 —— 內(nèi)存空間和查詢性能 。
點(diǎn)擊復(fù)制文檔內(nèi)容
試題試卷相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1