Hibernate的優(yōu)化策略_第1頁
Hibernate的優(yōu)化策略_第2頁
Hibernate的優(yōu)化策略_第3頁
Hibernate的優(yōu)化策略_第4頁
Hibernate的優(yōu)化策略_第5頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、hibernate的優(yōu)化策略hibernate performance tuning (reprint, author: robbin fan)a. inverse =?inverse = false (the default)for oneway one-to-many associationsparentgetchildren ()add (child) / / insert childparent. getchildren ()delete (child) / / delete childinverse = truefor a two-way one-to-many associatio

2、nchild. setparent (parent); the session. save (child) / / insert ch訂dthe session. the delete (child)in a hierarchical structureparentdao, childdao,s encapsulation of crud leads to the ability to persist objects directly through the session interface, but rarely through association objects2. one -to

3、- many relationshipsa oneway relationship or a twoway relationship?parentgetch訂dren ().add (child) the touch action of the collection causes lazy collection initialization, which should be avoided without a secondary cache of the collectionselect * from child where parent_id 二 xxx;the performance fo

4、rmula:in general, avoid one-way connections and try to use a two-way connectionusing a two-way correlation, inverse 二 trueusing the dao interface to persist objects directly through the dao interface in the hierarchical structure, avoiding the ability to persist through association relationships3. m

5、any -to - one relationshipone-way many-to-one expresses foreign key storagethe flexible use of the many-to-one can avoid some unnecessary performance problemsthe meaning of the many-to-one expression is: 0. n: 1, many can be 0, can be 1, or n, which means that many - to one can express one-to-many,

6、one-to-one, many-to-one relationshiptherefore, a two-way many-to-one relationship can be configured, for example:what is the relationship between a table of four players playing mahjong, mahjong seats and mah-jongg people? it's a two-way many-to-one relationshipfour. one -to - oneit is associate

7、d with the primary keythis is the equivalent of breaking up large tables into smaller tablesfor example, break up large fields separately to improve performance of database operationshibernate,s one-to-one seems unable to be lazy and must be passed bytecode enhancementfive. set the list/bag/setone -

8、to - manythe list needs to maintain the index column, can,t be used for bi-directional associations, must be inverse 二"false", and be carefully used in some rare occasionsthere is no difference between a bag/seti personally prefer to use bagmany -to - manythere is a difference between bag

9、and set semantics2. it is recommended to use the setsix. a collection of filtering1 children 二 session. createfilter (parent getchildren (),z/where this .age > 5 and this .age < 10")a very large case for a one-to-many set element, especially for a large collection of pages:().getchildren

10、()setfirstresult (0). setmaxresults (10).in hibernate, supergetsession ()createfilter ()seven. the implicit polymorphism in the inheritance relationshiphql: from the objectcheck out all database tablespolymorphism 二"default" takes the current object, and all the inherited subclasses of the

11、 object, all at oncepolymorphism 二"explicit", which only takes out the current query objecteight hibernate second level cachethe famous n + 1 problem: from child, and then displaying the parent information of each subclass on the page, wi11 result in an n bar query to the parent table:sele

12、ct * from parent where id 二?select * from parent where id 二?the solution1. the eager fetchsecondary cachenine.the relationship between the inverse and the secondary cachewhen using the collection cache:the hibernate maintains the collection cache by using parent getchildren ()inverse 二 /true,/, whic

13、h directly operates on the child and fails to maintain the collection cache! results in cache dirty datathe collection cache should be avoided in the case of a two-way correlation, inverse 二 trueten. the hibernate secondary cache is a magic weapon for improving web application performanceoltp types

14、of web applications, because the application server side can be clustered horizontally, the ultimate system bottleneck always runs away from the database access;which framework minimizes database access, reduces database access pressure, and which framework provides more performance; caching strateg

15、ies for databases:object cache: fine granularity, in view of the level of table records, transparent access, under the condition of without changing the program code can greatly improve the performance of web applications object caching is the magic weapon of orm.the quality of the object cache depe

16、nds on the level of implementation of the framework, which is the most powerful open source orm for the known object cachequery cache: coarse-grained, applied to a situation where data is not high in real-time, for query result sets11. the application context determines the system architecturedo you

17、 need ormhibernate or ibatis?the adoption of orm determines the database designhibernate:tend to fine granularity design, object-oriented, the big table is split into multiple correlation of the small table, eliminate redundant column, through the second level cache performance (dba relationship a t

18、aboo, but the cache orm will break through the correlation performance bottlenecks); the performance bottleneck for hibernate is not the correlation, but the operation of the large tableibatis:tends to the coarse-grained design, to the relationship, as far as possible to merge the table, through the

19、 redundant of the table column, to eliminate the correlation there is no efficient caching method. the performance bottleneck for ibatis is not the large table operations, but the correlation.conclusion:the performance of the formulause a two-way one-to-many relation, not using one direction one-to-

20、manyflexible use of one direction is more relevantyou don,t have to go one-on-one, you have to replace itconfigure the object cache without the collection cachea pair of multiple sets uses bag, with a set for multiple setsthe inheritance class uses explicit polymorphismthere are fewer table fields,

21、and don,t worry about the list correlation. there is a second level cacheyou,ve recently begun to look at the performance issues of hibernate in your project, hoping to find time to learn about the hiberante performance optimization it is mainly about database connection pool technology, hibernate s

22、econdary cache, hibernate configuration optimization, etcrelationships:common correlation: not including a join table, which is the middle table such as:the create table person (personld bigint not null primary key, addressld bigint not null)create table address (addressld bigint not null primary key)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論