`
tedeyang
  • 浏览: 326625 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ibatis or Hibernate?

阅读更多

思来想去,觉得自己的项目还是用ibatis好。
今天看到ibatis上的一篇文章,颇有同感:
Here are is a record of my experiences with Hibernate on a recent web
project where I was the team lead and had complete control over choice of
technology. This message is in the spirit of theory vs. practice.

A wise programmer once told me that "Simple things should be simple and hard
things should be doable". I was recently on a new project where I was the
team lead and I made the choice to use hibernate. This was my first serious
hibernate project and I found out that in Hibernate simple things are not so
simple but the hard things are theoretically made easy by hibernate.
However, I needed the simple things 80% and the hard stuff about 20% of the
time.

In my particular situation I had a very well designed data model that was
built by a highly experienced data modeler. The data model was built a
couple of weeks before I joined this project as the team lead and it had
about 90 tables.

The task of mapping this data model to hibernate was not very easy, in the
end we went with a one table one class mapping. We had many association
tables that carried the reasons why the association was there in the first
place. So we had to expose the association tables as mapped hibernate
objects (This was also the recommendation of the Hibernate in Action book).

Developer productivity was the number one priority on this project, because
we had a very tight deadline which we met). The idea behind ORM is that the
developers would have only had to deal with the Java Objects but alas that
was not doable they all ended up with print outs of the data model on their
desks. After my experience with this project I do not sure that the goal of
cleanly separating the

Also many of our web pages had data on them that was very easy to grab via
SQL however it would have required a lot of code to traverse from one java
object to another to present those pages. Following the advice of the
Hibernate in Action book we ended up using report queries to get our data
out of the database. Almost every screen that we did had one or two report
queries.

The interesting thing is that the report queries in Hibernate turned out to
be more complex to write and figure out. We frequently had to write queries
in SQL then convert them to HQL. The whole idea of hibernate taking care of
generating the SQL for you did not pan out. We still had to write a lot of
queries.

Many of the tables we had a lot of relationships to many other tables and I
frequently found out that I could not map those relationships very easily to
hibernate. At first I was tempted to go to the data modeler and ask him to
change the relationships to make the hibernate mapping easier. The more I
understood the business problem the more I figured out that he had done a
great job and it was pointless to change the data model to try and make it
more hibernate friendly. For the record the data modeler was great to work
and he did not object to any changes that we requested.

So I made the decision not to map the complex relationships to hibernate.
Only simple relationships got mapped to hibernate, and this another
disappointment for me with ORM & Hibernate. It just seemed that I was always
trying to fit a square into a circle.

In the end I had one java class for each table in the database, only simple
relationships were mapped. Complex relationships were not mapped and that
simplified our project quite a bit and allowed us to get in on time. So we
needed up with a lot of report queries in HQL which made use of the new
operator in the HQL to stuff the results into java objects.

At the time I started this project I did not know much about iBATIS and I
knew a lot more about Hibernate. Developer productivity was one my keys
goals and I figured that it would be easier for me and my team to have
access to books on hibernate and there were more learning resources for
hibernate. If I was doing this project again I would have probably gone with
iBATIS since I eneded up using hiberante the iBATIS way!

My intuition as a programmer is that mapping statements to classes is better
than mapping classes to tables, simple because it more naturally fits the
principle that "simple things should be simple to do and hard things should
be double."(一字之误,这哥们真是不怕苦)

One of the key features of SQL is its clousure property every SQL query
returns a table. If some one was making an Object Query language they would
not be able to keep the colsure property or do projection in way that makes
sense. This is why I think that mapping objects to statements is a better
approach than mapping objects to tables.

I hope the write up of my experience was worth the time you spent reading
it.

Adib Saikali

分享到:
评论

相关推荐

    Spring与iBATIS的集成

    Spring与iBATIS的集成 iBATIS似乎已远离众说纷纭的OR框架之列,通常人们对非常流行的Hibernate情有独钟。但正如Spring A Developer's Notebook作者Bruce Tate 和Justin Gehtland所说的那样,与其他的OR框架相比...

    iBatis2.0文档

    相较于 Hibernate 和 Apache OJB 这些“一站式”ORM解决方案,iBatis 提供了一种“半自动化”的ORM实现方式。这意味着它在一定程度上依赖于手动编写 SQL 语句,并将其与 Java 对象映射起来,从而在灵活性和性能方面...

    iBATIS_DAO事务管理实现

    iBATIS DAO框架提供的事务管理模块能够应用于多种不同的场景,包括但不限于JDBC、Hibernate、JTA、SQLMap等。为了实现这一点,框架采用了特定的设计模式——桥梁模式(Bridge Pattern),来解耦事务管理和具体实现。...

    ibatis Guide

    ibatis,作为一种“半自动化”的ORM(Object-Relational Mapping,对象关系映射)框架,不同于Hibernate和Apache OJB等提供全面数据库封装的“一站式”ORM解决方案,它更侧重于SQL与POJO(Plain Old Java Object,...

    iBATIS 2.0 开发指南

    相较于其他 ORM(对象关系映射)框架如 Hibernate 和 Apache OJB 的“一站式”解决方案,iBATIS 提供了一种“半自动化”的 ORM 实现,允许开发者更加灵活地控制 SQL 语句的编写和执行。 #### 重要特点 - **“半...

    ibatis.doc

    iBATIS,作为一款“半自动化”的对象关系映射(ORM)框架,相较于Hibernate和Apache OJB等全栈式解决方案,提供了更为灵活的数据库交互方式。它的核心理念在于,允许开发者保留对SQL的直接控制,同时简化了Java与SQL...

    Struts Hibernate Ibatis Spring RAD WID

    -- Be familiar with popular web development frameworks and tools, such as Struts, Spring, Hibernate. -- Good knowledge of database systems and development. -- Familiar with DB2 development tools and ...

    ibatis_开发指南

    8. OR映射 - 对象关系映射(ORM)是iBATIS的核心特性之一,它将Java对象与数据库中的表进行映射,简化数据库操作。 9. iBATIS高级特性 - 包括数据关联(一对多、一对一)、延迟加载、动态映射、事务管理和缓存策略...

    ibatis文档

    iBATIS 提供了多种数据访问实现,包括 JDBC、Hibernate、Toplink、JTASQLMap 等,为开发者提供了灵活的选择。 #### 二、iBATIS DAO 实现与设计 ##### 2.1 DAO 设计模式 DAO (Data Access Object) 是一种常用的...

    ibatis开发相关

    - **OR映射**:即对象关系映射,是ibatis的核心功能之一,用于定义Java对象和数据库表之间的映射关系。ibatis支持简单的映射以及复杂的关联映射。 - **一对多关联**:通过配置文件定义一个Java对象与其多个子对象...

    iBATIS_2.0_开发指南

    与Hibernate、Apache OJB等“一站式”ORM解决方案相比,iBATIS更注重于SQL语句的手动编写,同时通过配置文件将SQL语句与Java对象之间建立映射关系。 #### 二、准备工作 - **下载iBATIS软件包**:首先需要从官方网站...

    IBatis2开发指南.pdf

    与Hibernate等完全自动化的ORM框架相比,IBatis更倾向于半自动化,即开发者需要手动编写SQL语句,但框架负责将SQL语句的结果映射到Java对象,简化了结果集处理的复杂性。 ### IBatis的核心概念 #### 1. ...

Global site tag (gtag.js) - Google Analytics