11 advantages of using hibernate

Source: Internet
Author: User

After studying ibatis for a while, I think hibernate has an irreplaceable advantage of ibatis.

1. Developers all know that hibernate allows us to operate databases in oo mode, which allows us to see the strength of hibernate and experience the convenience of operating data. But Gavin King said that the most dazzling thing about hibernate is the cache mechanism of hibernate, rather than operating the database in the oo way. Hibernate's cache mechanism is basically a level-1 cache session, level-2 Cache sessionFactory, and third-party cache such as ehcache. That is, the most powerful part of hibernate is its cache. Only by understanding this can we truly understand hibernate. The cache is too difficult for me to really understand.

2. maintainability: ibatis promotes the writing of SQL statements. It puts SQL statements into a separate xml file. This method has won the favor of many developers and is easy to maintain. However, hibernate also has this function and is more powerful than ibatis. Hibernate naming query/naming parameter query is to place hql statements in a separate xml file, which still allows people to manipulate data in an object-oriented manner, this is favored by a large number of developers who follow the oo method, instead of writing code in the oo method, and then changing their thinking and writing those SQL statements in a relational-oriented manner. However, hibernate not only does this, but its native SQL query method fully satisfies the preference of SQL statements. Like ibatis, it puts SQL statements in the configuration file.

3. Performance: I firmly believe that the performance of hibernate is not a problem. Think about how many large 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 directly write the stored procedure to the real performance bottleneck. However, first of all, we must confirm that this is really a performance bottleneck. I think we should not take it for granted that performance problems, the so-called performance problems have blocked many people.

In my opinion, the performance is nothing more than the number of SQL statements sent. Good performance, few SQL statements are sent, and poor performance means a large number of SQL statements are sent. Hibernate has done a very good job in solving performance problems.

With its caching mechanism, the use of third-party caches and database connection pools can better solve performance problems.

However, this is not enough. hibernate gives developers sufficient freedom to control performance issues on their own.

I think developers can optimize themselves in the following aspects:

A. Should jdbc placeholders always be used in query strings ?, Or use the named parameter: Do not use the string value in the Self-query to replace the extraordinary value.

B. Flush will affect the performance. Frequent refresh will affect the performance and minimize unnecessary refresh.

C. Cascade policy. Set the cascade policy correctly based on the relationship between several pairs. Check whether Cascade operation object B is required while operating object, for example, if the parent one is deleted in the parent-child relationship of one to two, you need to cascading delete the child one. In this case, cascade = "delete" can be set for the one end ", in this way, the child will be automatically deleted when you delete one, but the child operation will not affect the parent. Cascade has other property values, which can improve performance as long as they are correctly set.

D. lazy policies. Correctly Setting a delayed loading policy also improves the performance. In one-to-least or two-to-least mode, it is usually always necessary to delay loading the memory from the worker side. If lazy = "true" is set, the system first sends an SQL statement and loads itself to the memory. The cascade object is loaded only when required. lazy = "false ", then it loads itself and cascade objects to the memory at the same time.

E. In addition, the set performance (set, list, map, array) should be set correctly.

F. correct use of third-party caching. If there are not many write operations in read operations, the use of third-party caching can greatly improve the performance. For example, the cache policies of ehcache include: read-only, read-write and notstrict-read-write.

F. With the release of the new version of hibernate and the development of technology, I believe that the performance of hibernate will be better and better. All performance is not the reason for not using hibernate.

4. hibernate is not only an orm framework of the persistence layer, but also has many persistence operations on the dao layer.

Today, annotation has moved to the mainstream, and hibernate responds quickly, making xml deployment descriptors optional. Hibernate annotation handles large fields only by @ Lob.

Hibernate search encapsulates Lucene in a lightweight manner, making full-text search very simple.

Hibernate validator is considered to be the most reasonable verification method. It attaches the verification policy directly to the domain model of each layer, and does not require xml verification of web frameworks, there are no more non-null/null judgments in the code.

5. The persistence layer of jbpm and Jbpm Business Process Engine is implemented using hibenrnate. To use jbpm, hibernate is required. I think business process management is extremely important. Today, with the rapid development of soa, business process management is inevitable and necessary for implementing soa projects. 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 the first priority, and corresponding technologies are required to implement business process management. I think jbpm is the first choice in the Open Source Field. Therefore, in order to implement soa projects in the future, hibernate should be used to implement soa business process management.

6. As we all know, hibernate has moved the entity beans of the ejb2 era into history, and the jpa standard of ejb3 is just a subset of hibernate. The jsr specification request has a huge power. Without a variety of jsr specification requests, there will be no various application frameworks. Various Application Frameworks are just the implementers of the jsr specification requests. As the standard of the persistence layer, jpa guides the direction of the persistence layer orm framework. jpa also operates the database in an object-oriented way, rather than writing SQL statements. The standard is completely orm and SQL is not written. Do you have any reason not to follow it?

7. Spring + hibernate + model + variable parameters, which are a very powerful combination and correspond to common crud operations, you no longer need to repeat the code of the annoying and similar dao and manager layers. You only need to write the code once to complete a large number of crud operations. Although Ibatis also supports the paradigm, it is never better supported by hibernate.

8. Jboss and hibernate are jboss projects. hibernate is used for the persistence layer of all jboss projects. You know, most of the experts in the jsr standardization group come from jboss, to a certain extent, jboo leads the development direction of java. Using hibernate and following jboss does not deviate from java's development direction.

9. Gavin King, my favorite idol, not only invented the powerful hibernate, but also developed the equally powerful and elegant web 0. 2 Application Framework seam. He is a member of the ejb3.0 expert group and a leader in jpa standard requests. He is one of the most competent and authoritative leaders in the java field. Now, he leads the development of web bean, jsr299, the formulation of web bean specifications, and the response of global software giants such as ibm, oracle, bea, and apache. As you can imagine, Web beans are really beautiful, completely loosely coupled and strongly typed. All application components live in the context of an Application Component and cooperate with each other. At that time, there will no longer be various context environments, there will be no struts2 ActionContext, no spring ApplicationContext, no hibernate session, no persistence context, no transaction context, there is no longer a security context. All components live in a big family and everyone is happy to achieve peace in the world.

10. osgi: I think it is the most worth learning technology. With osgi, we can achieve real multi-module development and change the traditional development method. Now, with hibernate osgi, spring dynamic modul (osgi), struts 2 also supports osgi. Currently, eclipse is developed based on osgi. All the products of ibm websphere v6.1 and bea are restructured on osgi. spring application servers are also based on osgi and on EclipseCon2007, osgi has become a major topic. It is not surprising that Osgi is so well received because it has extremely powerful functions and changes the traditional software development method. Osgi uses a tree design model to divide a project into multiple modules. Each module is deployed and run independently. To put it bluntly, a project is divided into many plug-ins, each plug-in is independently developed and reused for full plug-and-play. It's so exciting. If the company's software development is based on osgi, there will be a large number of repeated osgi bundles, the company will accumulate a large number of intangible assets, software development will become faster and faster. Ibatis has not yet seen support for osgi.

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

In summary, hibernate has many outstanding features, but we do not know. Hibernate and ibatis are similar to the big girl who is interested in Xiaojia biyu. The big girl not only has all the big girl biyu, but also has a higher reputation, more respected, more sought after, and more promising future. Although she is also attractive, she is always better than she is.

Hibernate does not only work on the persistence of the dao layer, but ibatis does.

Choose hibernate, select the King of orm, select a more comprehensive work experience, select a more efficient way of work, select more profits; select Gavin King, follow the leaders; select jboss, follow the open-source trend and do not deviate from java's development direction.

Everything is not an excuse. Everything is developing, and hibernate will get better and better.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.