99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

Hibernate性能問(wèn)題怎么解決

本篇內(nèi)容主要講解“Hibernate性能問(wèn)題怎么解決”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Hibernate性能問(wèn)題怎么解決”吧!

公司主營(yíng)業(yè)務(wù):成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)推出當(dāng)雄免費(fèi)做網(wǎng)站回饋大家。

在使用Hibernate進(jìn)行分頁(yè)的過(guò)程中,如果你收到如下警告,那么這里就是一個(gè)潛在的Hibernate性能問(wèn)題點(diǎn):

WARNING: firstResult/maxResults specified with collection fetch; applying in memory!

出現(xiàn)這個(gè)警告的直接后果是:無(wú)論你想要看第幾頁(yè)的數(shù)據(jù),從Hibernate打印出的SQL來(lái)看它總是查詢了所有滿足條件的結(jié)果。這是為什么呢?來(lái)看看這句警告所在的代碼,它位于org.hibernate.hql.ast.QueryTranslatorImpl中,部分摘錄如下:

  1. view plaincopy to clipboardprint?  

  2. QueryNode query = ( QueryNode ) sqlAst;  

  3. boolean hasLimit = queryParameters.getRowSelection() != null && 
    queryParameters.getRowSelection().definesLimits();  

  4. boolean needsDistincting = ( query.getSelectClause().isDistinct() || hasLimit ) && 
    containsCollectionFetches();  

  5. QueryParameters queryParametersToUse;  

  6. if ( hasLimit && containsCollectionFetches() ) {  

  7. log.warn( "firstResult/maxResults specified with collection fetch; applying in memory!" )  

  8. RowSelection selection = new RowSelection();  

  9. selection.setFetchSize( queryParameters.getRowSelection().getFetchSize() );  

  10. selection.setTimeout( queryParameters.getRowSelection().getTimeout() );  

  11. queryParametersqueryParametersToUse = queryParameters.createCopyUsing( selection );  

  12. }  

  13. else {  

  14. queryParametersqueryParametersToUse = queryParameters;  

  15. }  

  16. List results = queryLoader.list( session, queryParametersToUse );  

  17. QueryNode query = ( QueryNode ) sqlAst;  

  18. boolean hasLimit = queryParameters.getRowSelection() != null && 
    queryParameters.getRowSelection().definesLimits();  

  19. boolean needsDistincting = ( query.getSelectClause().isDistinct() || hasLimit ) && 
    containsCollectionFetches();  

  20. QueryParameters queryParametersToUse;  

  21. if ( hasLimit && containsCollectionFetches() ) {  

  22. log.warn( "firstResult/maxResults specified with collection fetch; applying in memory!" );  

  23. RowSelection selection = new RowSelection();  

  24. selection.setFetchSize( queryParameters.getRowSelection().getFetchSize() );  

  25. selection.setTimeout( queryParameters.getRowSelection().getTimeout() );  

  26. queryParametersqueryParametersToUse = queryParameters.createCopyUsing( selection );  

  27. }  

  28. else {  

  29. queryParametersqueryParametersToUse = queryParameters;  

  30. }  

  31. List results = queryLoader.list( session, queryParametersToUse );  

關(guān)鍵在于if ( hasLimit && containsCollectionFetches() 這句判斷,如果滿足了這個(gè)條件,RowSelection將會(huì)被重新生成,原本分頁(yè)需要的firstRow和maxRows屬性將會(huì)丟失,后面的數(shù)據(jù)庫(kù)分頁(yè)自然也無(wú)法進(jìn)行。Hibernate這么做的原因從代碼上也很容易理解,如果查詢需要限制條數(shù)(limit/offset)并且需要fetch結(jié)合對(duì)象,則重新生成RowSelection,進(jìn)一步解釋,就是當(dāng)一個(gè)實(shí)體(A)和另一個(gè)實(shí)體(B)是One-To-Many關(guān)系的時(shí)候,一個(gè)需要fetch的典型查詢語(yǔ)句是“select distinct a from A a left join fetch a.b”,由于1個(gè)A可能對(duì)應(yīng)多個(gè)B,這個(gè)時(shí)候數(shù)據(jù)庫(kù)查詢的結(jié)果條數(shù)和需要生成的A對(duì)象的條數(shù)可能不一致,所以無(wú)法利用數(shù)據(jù)庫(kù)層的分頁(yè)來(lái)實(shí)現(xiàn),因?yàn)槟阏嬲敕猪?yè)的是A而不是A left join B。出現(xiàn)這個(gè)警告就是提醒你這個(gè)查詢實(shí)際上是查詢了所有滿足條件的數(shù)據(jù),Hibernate是在內(nèi)存中對(duì)其進(jìn)行了假分頁(yè)的處理。

這樣,對(duì)于查詢結(jié)果比較多的情況無(wú)疑是一個(gè)Hibernate性能上的潛在威脅。碰到這樣的情況,將Many的查詢進(jìn)行分開也是一種解決辦法。

到此,相信大家對(duì)“Hibernate性能問(wèn)題怎么解決”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

網(wǎng)站題目:Hibernate性能問(wèn)題怎么解決
網(wǎng)頁(yè)URL:http://www.yijiale78.com/article38/pchepp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化用戶體驗(yàn)、電子商務(wù)、動(dòng)態(tài)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站