版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年福建南安市城乡水务集团有限公司招聘30人备考考试试题附答案解析
- 2026广东广州市华南理工大学医院合同制人员招聘2人备考考试题库附答案解析
- 2026北京市顺义区卫生健康委员会招聘事业单位高层次人才3人参考考试试题附答案解析
- 监狱生产安全管理制度
- 2026年楚雄州武定县公安局特巡警大队招聘辅警(2人)备考考试试题附答案解析
- 2026年阜阳市临泉县直水务和顺幼儿园招聘保育员备考考试题库附答案解析
- 2026春季江西赣州石城县西外公立幼儿园教职工招聘参考考试试题附答案解析
- Andr移动终端基础开发 4
- 公路安全生产巡查制度
- 备考2024年甘肃省白银市辅警协警笔试笔试测试卷(含答案)
- 湖南省益阳市2024-2025学年高一(上)期末考试物理试卷(含答案)
- 自愿退出豁免协议书范文范本
- 重庆市配套安装工程施工质量验收标准
- 机器人实训室规划建设方案
- 综合布线办公楼布线方案
- 鞍钢检验报告
- 河南省信阳市2023-2024学年高二上学期期末教学质量检测数学试题(含答案解析)
- 北师大版七年级上册数学 期末复习讲义
- 2023年初级经济师《初级人力资源专业知识与实务》历年真题汇编(共270题)
- 气穴现象和液压冲击
- 公民健康素养知识讲座课件
评论
0/150
提交评论