Today I went to the Java Programmer's recruiting information and saw that some companies also need to master the framework of the Ibatis persistence layer in addition to the hibernate, so I searched the internet for a bit, and it was a nice piece of writing.
I in the initial selection, considering Ibatis and hibernate different, originally intended to choose Hibernate, in the process of research found ibatis characteristics, after analysis and comparison, I chose Ibatis. Now I have used Ibatis to complete a small and medium sized project. This project is very satisfying in terms of performance, maintainability and scalability.
in the process I am also constantly discussing with people who have used or are using hibernate. And I am also constantly follow the development of hibernate.
In the end, my conclusion is that Ibatis's choice is very correct, and the more I use it, the more I like it.
Of course, my understanding of Ibatis and Hibernate is very limited, so the mistakes of some of the points about hibernate are expected to be corrected by the Hibernate master.
1. Ibatis features are easy to master
Ibatis Characteristics of the document to see half a day to two days can be mastered. Hibernate may take 3 times times more time to master.
2.iBatis features are easier to optimize for SQL
we should all agree on this. Also, the SQL generated by hibernate is too ugly. In view of the fact that some friends mention SQL is not very important. I want to emphasize my experience here, the bottleneck of the general system performance is on the database. So this is a very important advantage after comparing Ibatis and hibernate.
the 3.iBatis feature is fine grained optimization
3.1 For example I have a table, this table has several or dozens of fields, I need to update one of the fields, IBatis is very simple, execute a sqlupdate table_a SET column_1= #column_1 # WHERE id= #id # But using hibernate is more troublesome, and by default hibernate will update all fields. Of course I remember hibernate has an option to control only the fields that have been modified, but I'm not quite sure about the negative effects of this feature, so ibatis and hibernate compare, Ibatis advantages are obvious.
3.2 I need to list some of the contents of a table, with Ibatis, the advantage is that you can read a lot of data from the database, save traffic Select ID, NAME from Table_with_a_lot_of_column where
3.2.1 Generally hibernate will select all the fields. For example, one of the above tables has 8 fields, of which there are one or two relatively large fields, varchar (255)/text. Why should I choose them in the above scene?
3.2.2 with Hibernate, you can't set these two unwanted fields to lazy load, because there are many places that need to load the entire domain object one at a time. This time will be able to show the benefits of Ibatis.
3.2.3Hibernate also has a scheme to generate javabean/map/object[] (thanks to LEELUN/CJMM), but in this case it can produce a lot of redundant class. Map/object[] The way should be good, I prefer this way.
3.3 If I need to update a record (an object), if you use Hibernate, you need to select the object now, and then do update. This is two SQL for the database. and Ibatis only need an update of SQL on it. Reducing the interaction with the database at once is important for performance improvement.
4. The development dimension
4.1 Development efficiency, I think ibatis and hibernate should be about the same.
4.2 maintainability, I think ibatis better. Because Ibatis SQL is saved to a separate file. Hibernate may, in some cases, save sql/hql in Java code.
5. Operating Efficiency
5.1 Without considering the cache, the IBatis should be faster or more than hibernate (depending on the actual situation).
of course, Ibatis and hibernate have bigger drawbacks than that.
1. Different database types of support is not good, if you want to develop the system is to be in the pair of data transfer between, it may be better to use hibernate.
2. The default cache support is bad, but hibernate cache support is not very good, and very complex. Especially for the application of large concurrent volume. So I prefer to manage the cache myself.