For a new project using Spring with JDBCTemplates, iBatis/myBatis or Hibernate?

Marco picture Marco · Jul 7, 2011 · Viewed 14k times · Source

Hi there we are starting a project in which we have to make the decision between using Spring JDBCTemplates, iBatis/myBatis or Hibernate for our persistence layer. I am more or less familiar with the concepts from both of them but i am wondering what people currently tend to use.

My requirements are:

  • keep everything as simple as possible
  • easy learn and use
  • high performance
  • optimal developer productivity
  • must be usable with Spring 3

As noted we would like to keep everything as simple as possible. My preference tends to lean toward iBatis/myBatis because it looks easier to use and we do not need a real OR Mapper. But i am really looking forward to learn from the guys that use these frameworks.

Answer

xflorian picture xflorian · Jul 7, 2011

I advise you to have a look at minuteproject reverse-engineering solution for spring/hibernate/ibatis and also JPA(2), since it fulfill your development requirement. There is one thing that it does not generate (yet) is jdbctemplate.

Before opting for a technology, I will review all your points that fit in the minuteproject approach.

  • keep everything as simple as possible: Let minuteproject generates for you the code you need for persisting in iBatis (sqlMaps), in Hibernate (hbm files), in JPA (orm file or annotated entities). But all the additional framework integration: spring configuration, a comprehensive DAO stack (not limited to basic CRUD ops). It can correspond from 20 to 40% of your Application artifacts and time.
  • easy learn and use: your model becomes your technology tutorial! Learn from what has been generated. You can of course extend it for your specific need.
  • high performance: in the minuteproject track for Spring/hibernate or Spring/JPA: minuteproject provides ehcache configuration generation integrated with orm product. It provides and avanced dao layer with tuned query that you just have to reference.
  • optimal developer productivity: It helps you focusing on your real business and not all the tedious orm / dao tasks. It flattens the technology learning curve.
  • must be usable with Spring 3: The spring artifacts are comptible with 2.5+

But the best one that can judge is you, so try it on you model. To have a quick overview of the possibility start /bin/start-console.(cmd/sh), point to your database and chose a generation track. It should normally take a few minutes if your database is (mysql, db2, oracle, hsqldb have default value such as hibernatedialect preset). To go more advance use the configuration (it is for all db).

Regarding to which technology to use, personally I have production experience with all of them, but I would consider that the bidirectional aspect of orm frameworks such as hibernate is a strong point over unidirectional sqlmap. It saves configuration and graph navigation is intuitive.

A goody: Escaping special character such as ', is including in orm frameworks. And this is a problem you would commonly face while performing native sql in sqlmap such an insert of a lastname = 'o'hara'...

I would go for Hibernate (among the choice you mention), but go for JPA2 (if you would have included it). If you want real extra productivity integrate querydsl for compilable criteria API in it.