Hibernate is doing a very good job of solving performance problems. With its caching mechanism, the use of Third-party caching and database connection pool, a better solution to the performance problem. But that's not enough, Hibernate gives developers enough freedom to let developers control performance problems themselves.
Learning a period of ibatis, I think hibernate has ibatis irreplaceable advantage.
1. Developers know that hibernate lets us manipulate the database in an OO way, which allows us to see the power of the hibernate and experience the convenience of manipulating data. But Gavin King says the most dazzling thing about Hibernate is the hibernate caching mechanism, rather than manipulating the database in an OO manner. The hibernate caching mechanism is nothing more than a first-level cache session, a level two cache sessionfactory, and a third-party cache such as Ehcache. Hibernate is the most powerful place is its cache, understand this ability to truly understand hibernate. Caching is so difficult that I have not really understood it yet.
2, maintainability: Ibatis to promote the write SQL statement, it will put the SQL statement into a separate XML file, this way won the favorite of many developers, a word, easy to maintain. But hibernate also has this function and is more powerful than Ibatis. Hibernate named query/named parameter query, is to place the HQL statement in a separate XML file that still allows people to manipulate the data in an object-oriented manner, which is much like the OO-style developer, without the need to write the code in OO and then change the mind, Write those SQL statements in a relationship-oriented way. But hibernate not only did these, it's native SQL query, fully satisfy the preferences of SQL statements, it is like Ibatis, the SQL statement in the configuration file.
3, performance: I firmly believe that the hibernate performance problem is not a problem. Think of so many small and medium-sized projects are using Hibernate, you still doubt hibernate performance? After spring consolidates hibernate, it is entirely possible to use spring-integrated JDBC or direct write stored procedures where the real performance bottleneck is. But first of all, this is really a performance bottleneck, I think, should not take for granted the problem of performance, so-called performance problems to hinder a lot of people.
I think that the performance of the good or bad is to send the number of SQL statements. Good performance, fewer SQL statements sent, poor performance, is to send a large number of SQL statements. Hibernate is doing a very good job of solving performance problems.
With its caching mechanism, the use of Third-party caching and database connection pool, a better solution to the performance problem.
But that's not enough, Hibernate gives developers enough freedom to let developers control performance problems themselves.
I think developers can tune themselves in the following ways:
A, in the query string, should always use the JDBC placeholder? , or use named parameters: Do not use string values from queries to replace the very measure.
b, flush will affect performance, frequent refresh impact performance, minimize unnecessary refresh.
C, Cascade strategy, in several pairs of relationships, the correct setting of Cascade strategy, want to clear in the operation of object A and whether the Cascade operation object B, such as in one to many parent-child relationship, delete father one, need to cascade Delete Child many, then one of the end can be set Place cascade = "Delete" so that when you delete one, the child is automatically deleted, but the action of the pair does not affect the parent. Cascade also has other property values that can improve performance as long as the settings are correct.
D, lazy policy, the correct setting of the deferred load policy will also improve performance, in one to many or many to many, usually should delay loading the many side of the memory. Set lazy = "true" to send the SQL statement first, load itself into memory, load the cascading object when needed, and lazy= "false" to load both itself and the Cascaded object to memory.
E, and also the performance of the collection (set, list, map, array), should be set correctly.
F, the correct use of third-party caching, in the read operation frequently write operations, the use of Third-party caching can greatly improve performance, such as Ehcache cache strategy: 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 hibernate performance will be more and more good, all performance is not the reason not to use hibernate.
4, hibernate not only as a persistent layer of the ORM framework exists, it in addition to the DAO layer of the persistence of operations, there are many.
As the annotation annotation has gone mainstream today, hibernate quickly responds by making the XML deployment descriptor optional. Hibernate annotation processing of large characters is just a @lob.
Hibernate search has a lightweight encapsulation of lucene, and Full-text search becomes very simple.
Hibernate Validator is considered to be the most reasonable authentication method, and the validation strategy is attached directly to the domain model domain of every layer, which is no longer needed to validate the XML method of the Web framework, and there is no longer a large number of non-null/null judgments in the code.