版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二四年度设备采购合同范本及其技术参数说明书
- 二零二四年医疗器械设备采购租赁合同
- 北京城市学院《会计信息系统》2023-2024学年第一学期期末试卷
- 二零二四年度瓷砖产品代言人合同
- 2024年度人员招聘服务合同含猎头费与员工培训
- 2024年度房地产营销与销售代理合同
- 二零二四年度融资租赁合同详细条款及补充协议
- 辽宁事业单位2024年度护士聘用合同书
- 2024年度融资租赁合同:某企业租赁某设备进行生产
- 手术疼痛评估
- 标准中介服务合同样本
- 河北省唐山市部分学校2024-2025学年高一上学期11月期中联考化学试卷(含答案)
- 肠道菌群与炎症性肠病
- 2024-2030年中国汽车模具行业竞争模式及投资战略分析报告
- 2024年共青团入团积极分子考试题库及答案
- 市场营销策划(本)-形考任务三(第八~十章)-国开(CQ)-参考资料
- 国家开放大学《学前儿童游戏指导》期末复习题参考答案
- 英汉互译单词练习打印纸
- 网络安全教育ppt课件(图文)
- 新能源汽车故障诊断与排除PPT完整全套教学课件
- 2022版中国饲料成分及营养价值表
评论
0/150
提交评论