Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the advantages of Hibernate

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what are the advantages of Hibernate", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the advantages of Hibernate" this article.

1. Developers all know that Hibernate allows us to operate the database in the way of oo, which allows us to see the power of Hibernate and experience the convenience of manipulating data. But Gavin King says the most striking thing about Hibernate is Hibernate's caching mechanism, rather than operating the database in the way oo does. The caching mechanism of Hibernate is nothing more than first-level cache session, second-level cache sessionFactory, and third-party cache such as ehcache. That is, the big thing about Hibernate is its cache. Only by understanding this can we really understand Hibernate. Caching is so difficult that I haven't really understood it yet.

2, maintainability: ibatis promotes writing sql statements, which put sql statements into a separate xml file, this way has won the love of many developers, in a word, easy to maintain. But Hibernate also has this feature and is more powerful than ibatis. Hibernate named query / named parameter query, is to put hql statements in a separate xml file, it still allows people to manipulate data in an object-oriented way, which is loved by a large number of developers who follow the oo way, without having to write code in the oo way, and then change their mind to write those sql statements in a relationship-oriented way. But Hibernate doesn't just do that. Its native sql query completely satisfies the preference of sql statements. Like ibatis, it puts sql statements in the configuration file.

3. Performance: I firmly believe that Hibernate performance issues are not a problem. Considering that so many large, small and medium-sized projects are using Hibernate, do you still doubt the performance of Hibernate? After spring integrates Hibernate, you can use spring integrated jdbc or write stored procedures directly where there is a real performance bottleneck. But first of all, we have to confirm that this is really a performance bottleneck. I don't think we should take it for granted that the so-called performance problem has hindered a lot of people.

In my opinion, performance is nothing more than the number of sql statements sent. Good performance, send a few sql statements, poor performance, that is, send a large number of sql statements. Hibernate does a very good job of solving performance problems.

With its caching mechanism, using third-party caching and database connection pooling, the performance problem can be better solved.

But that's not enough. Hibernate gives developers enough freedom to control performance issues.

I think developers can tune themselves in the following areas:

A. Should you always use jdbc placeholders in query strings? Or use named parameters: do not use string values instead of non-constant values in your query.

B, Flush will affect performance, frequent refresh will affect performance, minimize unnecessary refresh.

C, Cascade strategy. Set the cascade policy correctly in several-to-several relationships to figure out whether cascading Operand B is needed while operating on object A. For example, in the parent-child relationship of one to many, the parent one is deleted and the child many is cascaded. In this case, the one end can be set to cascade = "delete". In this way, when the one is deleted, the child will be deleted automatically, but the operation on the child will not affect the parent. Cascade also has other property values that can improve performance as long as they are set correctly.

D, lazy policy, the correct setting of deferred loading policy will also improve performance, in one to many or many to many, you should always delay loading the side of many to memory. Set lazy= "true", first send sql statements to load yourself into memory, and only load cascading objects when needed; lazy= "false" will load both yourself and cascading objects into memory.

E, and the performance of the collection (set, list, map, array) should be set correctly.

F, the correct use of third-party cache, in the case of frequent read and write operations, the use of third-party cache can greatly improve performance, such as ehcache cache strategies are: read-only,read-write and notstrict-read-write.

G, with the release of the new version of Hibernate, and the development of technology, I believe that the performance of Hibernate will get better and better, all the performance is not the reason not to use Hibernate.

4. Hibernate exists not only as the orm framework of the persistence layer, but also as the persistence operation of the dao layer.

Today, when annotated annotation has gone mainstream, Hibernate responded quickly, making the xml deployment descriptor optional. Hibernate annotation's handling of large fields is just an @ Lob.

Hibernate search encapsulates Lucene lightweight, and full-text retrieval becomes very simple.

Hibernate validator is considered to be the most reasonable verification method, and the verification strategy is directly attached to the domain model domain, which runs through all tiers. Xml verification of which web framework is no longer needed, and a large number of non-empty / null judgments no longer appear in the code.

5. Jbpm, the persistence layer of Jbpm business process engine is implemented by hibenrnate, and it is necessary to use jbpm,Hibernate. I think business process management is extremely important, in the rapid development of soa today, if the implementation of soa project, business process management is inevitable and necessary. Because soa is the integration of business and it technology, and the integration of business process management and it infrastructure. In soa, business management is * bit, which requires the corresponding technology to implement the business process management. I think the jbpm in the open source field will be *. Therefore, in order to implement the soa project in the future, and to realize the business process management of soa, we should use Hibernate.

6. As we all know, Hibernate drives the entity bean of the ejb2 era into history, and the jpa standard of ejb3 is only a subset of Hibernate. The power of jsr specification requests is enormous. Without various jsr specification requests, there would be no various application frameworks, and various application frameworks are only implementers of jsr specification requests. Jpa, as the specification standard of the persistence layer, guides the direction of the persistence layer orm framework. Jpa also operates the database in an object-oriented way instead of writing sql statements. The norms and standards are completely orm, do not write sql, do you have any reason not to follow it?

7, Spring+Hibernate+ paradigm + variable parameters, this is a very powerful combination, corresponding to ordinary crud operations, you no longer need to repeat those annoying similar dao layer and manager layer code, only need to write once to complete all a large number of crud operations. Although Ibatis also supports paradigms, it is not as good as Hibernate.

8. Jboss,Hibernate is a project of jboss, and Hibernate is used in the persistence layer of all jboss projects. You know, most of the experts in the jsr specification group are from jboss. To some extent, jboo*** follows the development direction of java. Use Hibernate, follow jboss, do not deviate from the development direction of java.

9. Gavin King, my favorite idol, he not only invented the powerful Hibernate, but also developed the equally powerful and elegant web2.0 application framework seam. He is a member of the ejb3.0 expert group, the request of the jpa specification, and one of the most vocal and authoritative figures in the field of java. Now, he leads the development of web bean, the development of jsr299, the formulation of web bean specification, global software giants such as ibm, oracle, bea and apache have no objection, have responded one after another. Web bean, imaginably beautiful, is completely loosely coupled and strongly typed, and all application components live in a single application component context context and cooperate with each other. At that time, there will be no more context, no ActionContext for struts2, no ApplicationContext for spring, no session for Hibernate, no more persistence context, no transaction context, no more security context, all components live in a big family, and everyone is happy to achieve a great peace in the world.

10, osgi, I think the most worthwhile technology to learn now, with osgi, to achieve real multi-module development, change the traditional way of development. Now that Hibernate osgi,spring dynamic modul (osgi) is available, struts 2 also implements support for osgi. At present, eclipse is based on osgi, all the products of ibm's websphere v6.1 websphere Bea are refactored on osgi, and spring's application server is also based on osgi. On EclipseCon2007, osgi has become the main topic. It is not surprising that Osgi is treated like this, because he has extremely powerful functions that change the traditional way of software development. Osgi adopts tree design pattern, divides a project into multiple modules (bundle), each module is deployed separately, runs separately, to put it bluntly, is to divide a project into many plug-ins, each plug-in is developed separately, reused, to achieve complete plug-and-play. It's so exciting. If the company's software development is based on osgi, there will be a large number of reused osgi bundles, the company will accumulate a large number of intangible assets, software development will be faster and faster. Ibatis has yet to see support for osgi.

11. The community of Hibernate is very prosperous, while ibatis is relatively calm.

To sum up, there are many excellent features of Hibernate, but we don't know. Hibernate and ibatis, just like the big girl to the little Jasper, the big girl not only has all of the little Jasper, but also is more famous, more respected, more sought after and has a bright future. Although little Jasper is also very attractive, she is always better than a lady from a big family.

Hibernate does more than just persist the dao layer, which is exactly what ibatis does.

Choose Hibernate, choose the king of orm, choose a more comprehensive work experience, choose a more efficient way of working, choose more profits; choose Gavin King, follow the *; choose jboss, follow the trend of open source, and do not deviate from the development direction of java.

These are all the contents of the article "what are the advantages of Hibernate". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report