`
tedeyang
  • 浏览: 318979 次
  • 性别: 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框架相比...

    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简单实现与配置

    ibatis与hibernate一样,同样也是一种OR框架,OR框架有很多种,相对用的比较多的就是hibernate与ibatis,ibatis是一种白自动化的ORM的实现

    Spring与iBATIS地集成

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

    ibatis 开发指南(pdf)

    使用ibatis 提供的ORM 机制,对业务逻辑实现人员而言,面对的是纯粹的Java 对象, 这一层与通过Hibernate 实现ORM 而言基本一致,而对于具体的数据操作,Hibernate 会自动生成SQL 语句,而ibatis 则要求...

    ibatis框架

    我对Hibernate总体的感受就是,完全透明的OR映射,即使你不是很了解操作数据库的相关内容

    Hitis V1.2

    Hitis V1.2 (1)在ibatis中,不能取得实际执行的sql,也不能取得实际执行的sql所需要的参数数组,而Hitis可以 ...(3)在ibatis中,也须90%的情况... (2)i'm used local method or static method to ensure that:thread-safe

    MySQL Connector/J

    frameworks such as Hibernate, Spring's JDBC templates or Ibatis SQL Maps to do the majority of repetitive work and heavier lifting that is sometimes required with JDBC. This section is not designed to...

    springmybatis

    以前曾经用过ibatis,这是mybatis的前身,当时在做项目时,感觉很不错,比hibernate灵活。性能也比hibernate好。而且也比较轻量级,因为当时在项目中,没来的及做很很多笔记。后来项目结束了,我也没写总结文档。已经...

    Python ORM编程基础示例

    每种编程语言都具有自己的ORM库,java 的Hibernate、IBATIS;C#的Grove LINQ; Python 的 SQLAlchemy 1、映射技术 面向对象是从软件工程的基本原则(如耦合、聚合、封装)的基础由来 关系型数据库是从数学

    iuhyiuhkjh908u0980

    在工程目录下创建libs/hibernate/ ,放入 hibernate-tools-3.2.0.ga.jar jtidy-4aug2000r7-dev.jar build.properties project.name=sw project.version=1.0 basedir=. build.dir =${basedir}/build web.dir = ${...

    spring chm文档

    provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically. ------------------------...

Global site tag (gtag.js) - Google Analytics