Comparison between Ibatis and Hibernate

Source: Internet
Author: User

Ibatis: You need to write hibernate for SQL: the biggest difference is that SQL is automatically generated. The following are some details. choose either Hibernate or iBATIS. The features of Hibernate: Powerful Hibernate, good database independence, and strong O/R ing. If you are proficient in Hibernate, in addition, if Hibernate is properly encapsulated, the entire persistent layer code of your project will be quite simple, and few code needs to be written. The development speed will be fast and refreshing. The PO and Hibernte ing obtained by one-to-one ing of database fields are completely different. The essential difference is that the PO is flat, unlike the PO mapped by Hibernate, it can express the relationship between three-dimensional object inheritance, aggregation, and so on, which will directly affect the design idea of your entire software system. Hibernate provides a complete encapsulation of the database structure. Hibernate's O/R Mapping implements the poing between POJO and database tables, as well as automatic SQL generation and execution. Programmers often only need to define the poing relationship between POJO and database tables to complete the persistent layer operations through the methods provided by Hibernate. Programmers do not even need to be familiar with SQL. Hibernate/OJB will automatically generate the corresponding SQL based on the developed storage logic and call the JDBC interface for execution. The disadvantage of Hibernate is that it has a low learning threshold and a higher level of proficiency. In addition, how can we design O/R ing and balance the performance and object models, and how to make good use of Hibernate requires your strong experience and capabilities, but Hibernate is now a mainstream O/R Mapping Framework, from the richness of documents, product perfection, both versions are faster than iBATIS. IBATIS features: iBATIS is easy to get started with and is ready for use. It provides the Automatic Object binding function for database queries and provides good experience in SQL, for projects that do not have such high requirements on object models, it is perfect. The disadvantage of iBATIS is that the framework is still relatively simple and the functions are still missing. Although the data binding code is simplified, the entire underlying database query needs to be written by itself, and the workload is also large, it is not easy to adapt to quick database modification. When the system is under secondary development and cannot control or modify the database structure, iBATIS is more flexible than Hibernate. System data processing capacity is huge and performance requirements are extremely demanding. This often means that we must use highly optimized SQL statements (or stored procedures) to achieve system performance design indicators. In this case, iBATIS has better controllability and performance. Comparison of actual development: 1. iBATIS requires a handwritten SQL statement or a part of it. Hibernate can basically generate it automatically and occasionally write Hql. For the same requirement, the workload of iBATIS is much larger than that of Hibernate. Similarly, if modification to database fields is involved, there are very few changes to Hibernate, while iBATIS should modify those SQL mapping areas one by one. 2. iBatis can be fine-grained. For example, I have a table with several or dozens of fields. I need to update one of the fields. iBatis is very simple, execute an SQL UPDATE TABLE_A SET column_1 = # column_1 # WHERE id = # id # However, It is troublesome to use Hibernate. By default, hibernate updates all fields. Of course, I remember that hibernate has an option to control only the modified fields, but I am not sure about the negative effects of this function. For example, I need to list part of a table. When using iBatis, the advantage here is that I can read a lot of data FROM the database and save the flow of SELECT ID, NAME FROM TABLE_WITH_A_LOT_OF_COLUMN WHERE... generally, Hibernate Selects all fields. For example, there is a table with eight fields, two of which are relatively large, varchar (255)/text. In the above scenario, why should I select them? If hibernate is used, you cannot set the two unnecessary fields as lazy load, because the entire domain object needs to be loaded at one time. At this time, we can see the benefits of ibatis. If I want to update a record (an object), if hibernate is used, select the object and update it again. This is two SQL statements for the database. IBatis only needs an update SQL statement. Reducing one interaction with the database is very important for performance improvement. Www.2cto. com3. in terms of development efficiency, I think the two should be similar. In terms of maintainability, I think iBatis is better. Because iBatis SQL is saved to a separate file. In some cases, Hibernate may protect SQL/hql in java code. Compared with Hibernate "O/R", iBATIS is Is An ORM implementation of "SQL Mapping. IBATIS focuses on the poing between POJO and SQL. That is to say, iBATIS does not automatically generate SQL Execution for programmers at runtime. The specific SQL needs to be compiled by the programmer, and then map the parameters required by the SQL and the returned result fields to the specified POJO through the ing configuration file. Using the ORM mechanism provided by iBATIS, for business logic implementers, they are faced with pure Java objects. This layer is basically consistent with the implementation of ORM through Hibernate, while for specific data operations, hibernate automatically generates SQL statements, while iBATIS requires developers to write specific SQL statements. Compared with Hibernate, iBATIS provides more free space for system design with the workload of SQL development and database portability concessions. 4. When the running efficiency is not considered as cache, iBatis should be faster or more efficient than hibernate.

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.