Hibernate or Mybatis

The biggest difference between Hibernate and the iBATIS DB Layer, or more specifically SQL Maps, is that Hibernate is an Object Relational Mapper, whereas SQL Maps (as the name implies) is an SQL Mapper. The difference?

An Object Relational mapper maps Objects to database entities directly. In the case of Hibernate, all SQL is generated based on those mappings. Custom SQL is handled via HSQL, an Object Oriented query language that basically facades real SQL.

A SQL mapper maps your Java Objects to real SQL statements. The SQL statements are not generated and the mapping is completely independent of the database entities and relationships.

In terms of features, I don’t know that they can be directly compared easily, as the products are really in different classes. The general rule of thumb is: if you are starting a new project and you’re in full control of your object model and database design, Hibernate is a good choice of O/R tool.

However, if you are accessing any 3rd party databases (e.g. vendor supplied), or you’re working with a legacy database, or even just a really poorly designed database, then an O/R mapper might not be capable of handling the situation. That’s were an SQL Mapper comes in handy. With an SQL Mapper, there are no restrictions to the mapping between the Object Model and the Data Model –even if either is poorly designed (which happens a lot in the real world –don’t forget about secondary databases that you might have to access…).

There are a lot more O/R mappers around, because they are quite simply one of the “holy grails” of computing. Examples include Hibernate, TopLink, CocoBase and all JDO implementations.

SQL Mappers are harder to come by, but really any embedded SQL system can be considered an SQL Mapper, including iBATIS SQL Maps, Oracle SQLJ, Forte 4GL Embedded SQL, Pro*C Embedded SQL etc. In the case of iBATIS SQL Maps, you can think of it as SQL embedded in XML.

In terms of performance, the old SQL Mappers embedded in compiled languages are probably the fastest raw performing solutions because they are fully compiled. O/R mappers have to do a lot more work and usually involve reflection. iBATIS SQL Maps in this respect is more like an O/R mapper, as it is not fully compiled and uses reflection (however full compilation is not entirely out of the question).

As for who is actually the fastest, I don’t believe anyone knows for sure. Everyone has a different answer. If you ask some vendors, they’ll tell you that their product is N times faster than raw JDBC without caching (starts with “c” ends with “ocobase” –not likely). :-)

I believe that the performance of these frameworks will largely depend on how you use them. If you have a very straight-forward CRUD app, with Table-Class mappings, then an O/R mapper has a number of advantages in terms of simplicity and performance. However, if you have a complex/poor/large/etc. database model beyond your control, then an SQL mapper might be the only solution that works for you.

Generally an O/R mapper can create much more efficient mappings and cache strategies because it “knows” more about both the object model and the database. However, if it came down to a complex data transformation (say, flattening a relational parent/child tree), then an SQL mapper could likely do it much faster because it could take advantage of more efficient SQL. Generally you’ll have more control over the exact processing with an SQL Mapper, and therefore it offers more opportunity for tuning complex queries.

My suggestion: Try more than one. Do a couple of proofs of concept for your project and implement a deep “vertical slice” that you can test performance with. Every project will be different. For some, you’ll want Hibernate, others you’ll want iBATIS SQL Maps, others still you’ll want to use TopLink or maybe even raw JDBC.

For this reason, I think it’s more important and useful to learn how to evaluate and test these tools quickly and effectively; and it is less important to learn only one of them exclusively or even very well. Practice and get better at making good decisions, and worry less about finding “the grail”.

In the end the choice is yours and nobody can tell you what the right one is. Trust only yourself, draw your own conclusions and do lots of testing!


Clinton Begin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值