Hibernate的优化策略_第1页
Hibernate的优化策略_第2页
Hibernate的优化策略_第3页
Hibernate的优化策略_第4页
Hibernate的优化策略_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、hibernate的优化策略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等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论